1

I have a component called

<checkbox_component  ng-repeat="ccc in cmp.teachers1" 
label="{{ccc.name}}" objectValue="{{ccc}}"></checkbox_component>

Should I declare objectValue as a NgAttr? but that doesn't work I think it only works with strings.


Here I want to complain, I find it relatively difficult to communication between components. Lets say I have a component which is a page and then it has some components of mine on that page, its slightly hard to communication from the child components to the parent components and back again, either due to my lack of knowledge or some limitation.

Phil
  • 46,436
  • 33
  • 110
  • 175

2 Answers2

1

You are right. @NgAttr can only work with literal values but you can use @NgTwoWay

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
1

Either use the @NgTwoWay annotation or the NgModel Decorator:

<checkbox_component  ng-repeat="ccc in cmp.teachers1" ng-model="ccc"></checkbox_component>
@NgComponent(
  selector: 'checkbox_component[ng-model]',
  ...
)
class CheckboxComponent  {
  NgModel _ngModel;
  CheckboxComponent(this._ngModel);

  ...
}

Take a look at how NgModel is used at class InputCheckbox here.

Ozan
  • 4,345
  • 2
  • 23
  • 35