angularjs - Directive with isolated scope unexpectedly accessing parent scopes -
angularjs - Directive with isolated scope unexpectedly accessing parent scopes -
i have created directive my-directive
isolated scope, looks able access property div1
of $rootscope
, property div2
of parent scope $scope
of controller1
.
what missing?
javascript:
angular.module('app', []) .controller('controller1', ['$scope', function ($scope) { }]) .directive('mydirective', [ function () { return{ restrict: 'a', replace: true, scope: { mydirective:'=' } }; }]);
html:
<body> <div id="1" ng-app="app" ng-init="div1='div1'"> <div id="2" ng-controller="controller1" ng-init="div2='div2'"> <div id="4" my-directive="value" ng-init="div4='div4'"> {{div4}}<br/> {{div1}}<br/> {{div2}}<br/> </div> </div> </div> </body>
output:
div4 div1 div2
you should utilize transclude function within directive, otherwise values bound parent scope. check this: http://pucksart.com/transclude-big-mistery/
angularjs angularjs-directive angularjs-scope
Comments
Post a Comment