0

I have a child directive inside a parent directive. I want the child directive to be completely generic and not have to rely on the naming of the parent directive's controllerAs syntax. To explain myself better here is what i Have

Parent Directive

templateUrl: '/apps/common/myParentDirective.html',
controller: 'myParentDirectiveController',
controllerAs: 'vm'

Child Directive (this has to inherit parent scope and watch a property named 'dynamicFields' on the scope of the parent directive. Right now i have the code below

$scope.$watch('vm.dynamicFields', function (newVal) {
    if (!newVal) {
        return;
    }

    // do something with dynamicfield
});

I want this directive to be re-usable and don't want to be tied into using vm.dynamicFields. Can i simply use 'dynamicFields' as it is guaranteed that the name of the field on the scope will always be the same but it not guaraneteed that the parent directive would be using 'vm' or 'somethingelse'

user205892
  • 311
  • 1
  • 8
  • *Can i simply use 'dynamicFields...'* - of course, you can't. That's the point of creating isolated scope. To not rely on scope hierarchy, whatever it is. If it was the question, this is as simple as that. – Estus Flask Feb 06 '17 at 08:45
  • Possible duplicate of [Angularjs directive: Isolated scope and attrs](https://stackoverflow.com/questions/14300986/angularjs-directive-isolated-scope-and-attrs) – Paul Sweatte Jul 12 '17 at 15:38

0 Answers0