【问题标题】:angular 1.5 component to call the parent scope methodangular 1.5 组件调用父作用域方法
【发布时间】:2017-08-04 10:32:45
【问题描述】:

我有一个 html 模板 + 控制器。 我在那里添加了一个组件:

<ir irtrend="addIrTrend"></ir>

addIrTrend 是我的控制器范围内的一个函数。 我希望我的组件调用 addIrTrend 方法。 我给我的组件这样的 irtrend 参数:

bindings: {
    irtrend: '&'
}

并且它有一个可以 ng-click 的元素:

<td ng-repeat="item in items" ng-click="$ctrl.irtrend({item: item}">

据我了解,当点击 td 元素时,irtrend 方法 应该调用对父 ctrl "addIrTrend" 方法的引用。

实际上什么也没发生。

有什么想法吗?

谢谢!

【问题讨论】:

  • 您的示例代码是否正确?带有 ng-click 的列表片段,该函数没有右括号。

标签: angularjs angularjs-scope components parent


【解决方案1】:

实际上在irtrend 属性中你应该指定方法调用。

<ir irtrend="addIrTrend(item)"></ir>

同时将 ng-click 表达式正确地添加到右括号 $ctrl.irtrend({item: item})

【讨论】:

    猜你喜欢
    • 2017-07-27
    • 2017-12-18
    • 2017-12-15
    • 2020-10-20
    • 2023-01-08
    • 2016-12-22
    • 1970-01-01
    • 2016-10-23
    相关资源
    最近更新 更多