As a new Angular user, I am facing an issue that involves having two directives in my HTML code like this:
<parent-dir param="par">
<child-dir></child-dir>
</parent-dir>
And defining them in my JavaScript code as follows:
In the parent directive:
app.directive('parentDir', function(){
return {
restrict: 'E',
scope: {
param: '='
}
}
})
And in the child directive:
app.directive('childDir', function(){
return {
restrict: 'E',
require: '^parentDir',
controller: function($scope, $element){
<-- SHOULD I PUT WATCHER HERE -->
},
link: function(scope, element, attrs, parentdirCtrl){
<-- SHOULD I PUT WATCHER HERE -->
}
}
})
I'm unsure about where to place an optional $watch in the child directive in order to track all changes in the param model. While using $watch in the parent controller reflects all changes on the param in the parent directive, I'm struggling to pass this information to the child directive.