Angular Directives: scope vs bindToController

Ahmet Cetin picture Ahmet Cetin · Jan 24, 2016 · Viewed 11.5k times · Source

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?

Answer

eliagentili picture eliagentili · Feb 28, 2016

Think 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/