Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular Component Parent Function undefined arguments

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

like image 599
korteee Avatar asked Sep 21 '26 08:09

korteee


1 Answers

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}})"

Demo Plunker

like image 154
Pankaj Parkar Avatar answered Sep 24 '26 03:09

Pankaj Parkar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!