December 2014
Intermediate to advanced
346 pages
6h 14m
English
When a directive is not instructed to create its own isolate scope, it will inherit the scope of whatever scope it exists inside.
Suppose that you begin with the following skeleton application:
(index.html - uncompiled)
<div ng-app="myApp">
<div ng-controller="MainCtrl">
<my-directive>
<p>HTML template</p>
<p>Scope from {{origin}}</p>
<p>Overwritten? {{overwrite}}</p>
</my-directive>
</div>
</div>
(app.js)
angular.module('myApp', [])
.controller('MainCtrl', function ($scope) {
$scope.overwrite = false;
$scope.origin = 'parent controller';
});The most basic setup is to have the directive scope inherit from the parent scope that will be used by the directive within the link function. This allows ...
Read now
Unlock full access