0
.component(
  'testComponent',
 {bindings: {name:'<'},
  template: `{{$ctrl.name}}<br/>
             {{$ctrl.title}}<br/>
             {{test.name}}<br/>
             {{test.title}}<br/>
             {{name}}<br/>
             {{title}}<br/>`,
  controller: function (){
    this.name = 'abc';
    this.title = 'def';
  },
  controllerAs: 'test'
})

This code is to add a component to a module. There are written 6 expressions in template. But only second one, $ctrl.title is working well. The others are not binded properly. When I remove name from bindings, then $ctrl.name also works well. But AFAIK all the 6 expressions have to work.

What did I do wrong?

1
  • Don't say it "doesn't work" and leave it is that. Describe the problem. Describe what you are trying to accomplish. Commented Jun 11, 2017 at 17:34

1 Answer 1

1

Because here the binding '<' means one way binding Where are you using this component The name binding should be passed from where you are calling this component eg

<test-component>name='abc' </test-component>

This will work also remove controllerAs = test,if you are using $cntrl as it is default controllerAs of component and you are replacing it with test

Sign up to request clarification or add additional context in comments.

2 Comments

I should have shown you the full source code. I already tested '=', '=?' and '@'. Only '=?' works even that the value is not watched after initialization. I think not giving bindings option and giving it as '=?' work same, but it does not reflect the value changed after initalized once.
docs.angularjs.org/guide/expression I think my component works in the 'one-time binding' way, while it is not inteded.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.