.directive("abc",function(){
return {
scope:{
title:"@",
name:"=",
changeNum:"&"
}
/* 出现了scope就表示这个指令的scope是独立的,但如果要与外界联系,就要使用绑定策略*/
/*使用@符号可将本地作用域的变量与DOM属性的值进行绑定,即我们通过@得到title属性的值*/
/*使用=符号可将本地作用域上的属性与父级作用域上的属性进行双向绑定,即我们通过=得到name的引用。可以同值传递和引用传递的理解相结合*/
/*使用&符号可以对父级作用域进行绑定,以便在其中运行函数,简单说就是绑定函数用的*/
}
})
<div ng-controller="test">
<div>AngularJs指令的三种绑定策略</div>
<example title="titleExample" name="nameExample" send-message="parentSendMessage('example')">
</example>
</div>
directive:
myApp.directive("example",function(){
return {
restrict:"E",
scope:{
title:"@",
},
link:function($scope,element,attrs){
console.log($scope.title); ==> titleExample
}
}
})
directive:
myApp.directive("example",function(){
return {
restrict:"E",
scope:{
name:"=",
},
link:function($scope,element,attrs){
console.log($scope.name); ==> nameTest
}
}
})
//父级作用域的控制器
controller:
myApp.controller("test",function($scope){
$scope.nameExample = "nameTest"
})
directive:
myApp.directive("example",function(){
return {
restrict:"E",
scope:{
sendMessage:"&",
},
link:function($scope,element,attrs){
}
}
})
//父级作用域的控制器
controller:
myApp.controller("test",function($scope){
$scope.parentSendMessage = function(content){
alert(content);
}
})
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有