Angular directive automatically re-created when scope changes

Many of my directives (soon to become components) take their scope from variables set by other directives. Currently, in each directive I have to keep track of my area to see if this has changed, which seems to unnecessarily complicate the code. So I started using ng-if = "vm.ready" in my tag to restore the directive when I need it. But then the management of this state remains outside the scope of the directive, which is more difficult to maintain.

I am wondering if angular will provide such a mechanism if, when changing the scope of your directive, it will at least restore your directory controller.

thank

+4
source share
1 answer

Perhaps you can use $onInit()

After creating the controller instance, the initial values ​​of the bindings of the selection area will be bound to the properties of the controller. You can access these relationships as soon as they are initialized by providing a controller named $ onInit, which is called after all the controllers on the element have been built and their bindings initialized.

https://github.com/angular/angular.js/blob/master/src/ng/compile.js#L250

+1
source

All Articles