angularjs之directive中@=&

@father:<input type="text" ng-model="data"/>
        <me title="{{data}}">@</me>
        
=father:<input type="text" ng-model="msg"/>
        <you title="msg">=</you>
        
<he func="cli(str)">&</he>

接下来是主要的js代码:

 1 var app = angular.module("myApp", []);
 2             app.controller('myCtrl',['$scope',function($scope) {
 3                 $scope.cli = function(str) {
 4                     console.log(str);
 5                 }
 6 //                $scope.str = "this is he!";
 7             }])
 8             app.directive('me',function() {
 9                 return {
10                     restrict:"E",
11                     scope:{
12                         title:'@'
13                     },
14                     template:"<div>{{title}}@:<input type='text' ng-model='title'/></div>"
15                 }
16             })
17             
18             
19             app.directive('you',function() {
20                 return {
21                     restrict:"E",
22                     scope: {
23                         title:"="
24                     },
25                     template:"<div>{{title}}=:<input type='text' ng-model='title'/></div>"
26                 }
27             })
28             
29             app.directive('he',function() {
30                 return {
31                     restrict:"E",
32                     scope: {
33                         func:"&"
34                     },
35                     template:"<div><input ng-model='v'/><button ng-click='func({str:v})'>点击</button></div>"//在func里面加参数的写法
36                 }
37             })

总结:@就是在引用时要加{{}},且子元素不能改变父元素的model,=就是在引用时直接引用,不加{{}},子元素可以改变父元素的model,双向绑定,&是负责方法调用的,其中可以添加参数,如以上例子所示写法。

转载于:https://www.cnblogs.com/xueyuting/p/6761891.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值