html代码
<div ng-controller="MainController">
outside myDirective:{{myProperty}}
<div ng-init="myProperty='wow, this is cool'" my-directive>
inside myDirective:{{myProperty}}
</div>
</div>
1. 指令scope为false时
angular.module('myApp',[])
.controller('MainController', function($scope){
})
.directive('myDirective', function(){
return {
restrict: 'A',
scope: false,
template: '<div>Inside myDirective {{myProperty}}</div>'
}
})
2. 当scope为true时
angular.module('myApp',[])
.controller('MainController', function($scope){
})
.directive('myDirective', function(){
return {
restrict: 'A',
scope: true,
template: '<div>Inside myDirective {{myProperty}}</div>'
}
})
3. 当scope使用隔离作用域时
angular.module('myApp',[])
.controller('MainController', function($scope){
})
.directive('myDirective', function(){
return {
restrict: 'A',
scope: {},
template: '<div>Inside myDirective {{myProperty}}</div>'
}
})