Angular 组件父函数未定义参数
Angular Component Parent Function undefined arguments
我得到了一个绑定父函数的组件。我知道我必须使用非原始值作为参数,但我仍然未定义。这是怎么回事 ?这是演示我的问题的示例代码。
组件:
app.component('testComponent', {
template:'<button ng-click="$ctrl.hasStatus({val:700})">Test</button>',
bindings:{
hasStatus:'&'
},
controller:function() {
var ctrl = this;
}
})
家长:
<test-component has-status='hasStatus(statusObj)'></test-component>
在控制器中:
$scope.hasStatus = function(obj) {
console.log(obj) // undefined
}
还有 plunker
因为你的 has-status 属性函数有 hasStatus(statusObj)
,其中 statusObj
是对象的参数。这就是为什么你应该传递 JSON 中提到的状态 statusObj
属性,同时将参数传递给 hasStatus
方法。
ng-click="$ctrl.hasStatus({statusObj: { val: 700}})"
我得到了一个绑定父函数的组件。我知道我必须使用非原始值作为参数,但我仍然未定义。这是怎么回事 ?这是演示我的问题的示例代码。
组件:
app.component('testComponent', {
template:'<button ng-click="$ctrl.hasStatus({val:700})">Test</button>',
bindings:{
hasStatus:'&'
},
controller:function() {
var ctrl = this;
}
})
家长:
<test-component has-status='hasStatus(statusObj)'></test-component>
在控制器中:
$scope.hasStatus = function(obj) {
console.log(obj) // undefined
}
还有 plunker
因为你的 has-status 属性函数有 hasStatus(statusObj)
,其中 statusObj
是对象的参数。这就是为什么你应该传递 JSON 中提到的状态 statusObj
属性,同时将参数传递给 hasStatus
方法。
ng-click="$ctrl.hasStatus({statusObj: { val: 700}})"