Reputation: 2682
I got a component which binds a parent function. I know I have to use non-primitive values as arguments but I still get undefined. What's going on ? Here's a sample code that demonstrates my problem.
Component:
app.component('testComponent', {
template:'<button ng-click="$ctrl.hasStatus({val:700})">Test</button>',
bindings:{
hasStatus:'&'
},
controller:function() {
var ctrl = this;
}
})
Parent:
<test-component has-status='hasStatus(statusObj)'></test-component>
and in the controller:
$scope.hasStatus = function(obj) {
console.log(obj) // undefined
}
And the plunker
Upvotes: 3
Views: 710
Reputation: 136144
As your has-status attribute function has hasStatus(statusObj)
, where statusObj
is parameter of object. That's why you should pass status statusObj
property mentioned in JSON, while passing parameter to hasStatus
method.
ng-click="$ctrl.hasStatus({statusObj: { val: 700}})"
Upvotes: 3