angular directive scope
angular directive scope
1.当directive 中不指定scope属性,则该directive 直接使用 app 的scope;
2.当directive 中指定scope属性时,scope作用域有3种方式:
2.1 . = : 代表数据双向绑定,只要该属性发生改变 ,app(即父作用域) 中scope对应的值和 directive中对应的值将同时发生改变 ;
2.2 . @ : 代表数据单向绑定,该值的改变只会影响directive ,不会影响app(即父作用域) 其他值, 也就是孤立作用域 ;
2.3 . & :代表继承或者使用父作用域中scope绑定的方法。
下面用一个demo 来说明:
example:
directive html:
gmb-per
coffee directive code :
# module
angular.module('demo',[])
.controller 'myCtrl',($scope)->
$scope.gmbPerNotification_d = [1,2,3]
$scope.myalert = ->
alert(11)
#directive
pushNotificationApp.directive 'gmbPer',($timeout,$compile) ->restrict: 'AE'#terminal : truetransclude : true#replace : truetemplate:'121212'#replace : truescope:abc : '='gmbPerNotification_d : '='say : '&'controller : ($scope) ->#$scope.mytest = [1,2]link : (scope, element, attrs) ->console.log
转载于:https://www.cnblogs.com/rengised/p/5602461.html
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
