Since Angular v1.4, it's possible to do this:
scope: {},
bindToController: {
name: "="
}
instead of old way of doing:
scope: {
name: "="
},
bindToController: true
Except being more intuitive, is there any difference between them?
Since Angular v1.4, it's possible to do this:
scope: {},
bindToController: {
name: "="
}
instead of old way of doing:
scope: {
name: "="
},
bindToController: true
Except being more intuitive, is there any difference between them?
Share Improve this question edited Jan 24, 2016 at 15:29 Ahmet Cetin asked Jan 24, 2016 at 15:22 Ahmet CetinAhmet Cetin 3,8234 gold badges27 silver badges35 bronze badges 3- 2 You could, in theory, pass many parameters to the directive, and only bind a few of them to the controller. I can't think of any valid reason to do this, but it is possible. With the original syntax, it was all or nothing. – Claies Commented Jan 24, 2016 at 15:26
- 1 blog.thoughtram.io/angularjs/2015/01/02/… checkout this insightful article for a bit of explanation – Yerken Commented Jan 24, 2016 at 15:29
- Possible duplicate of bindToController: Object in directives – Estus Flask Commented Jan 24, 2016 at 21:07
1 Answer
Reset to default 13Think about bindToController as a migration path for future version of Angular.
We prefer to write directives (or components) with isolated scope and bind to controller the properties you want to pass.
Binding variables from scope will gradually disappear.
In the new release of angular (1.5) you don't need to use scope or bindToController, because the scope is isolated for default and for bind variables to controller you can use bindings.
This is also useful for preventing $scope use. Read this article if you want more info about that: https://toddmotto.com/no-scope-soup-bind-to-controller-angularjs/