关于angular的三个绑定策略 @、=、&

<!DOCTYPE html>
<html  lang="en" ng-app="MyModule">
    <head>
    <meta charset="utf-8">
        <script src="http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js"></script>
        <script src=".js"></script>

        <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    </head>
    <body>
           <div ng-controller="MyCtrl">
               <div class="panel panel-default">
                   <!-- @ -->
                   <div class="panel-title">
                       <drink flavor="{{ctrlFlavor}}"></drink>
                       <button ng-click="resetDrflavor()" class="btn btn-warnning">resetDrflavor</button>
                       <input type="text" name="" class="input" ng-model="ctrlFlavor">
                   </div>
               </div>

               <div class="panel panel-primary">  <!-- = --> 

                    <div class="panel-title">
                        <input type="text" name="" ng-model="eatFoodS">
                       <eat  eatfooda="eatFoodS"></eat>
                    </div>
               </div>
               <div class="panel panel-warning"><!-- & -->
                   <div class="panel-title">
                       <play aaa="ggg('嘿哟~')"></play>
                   </div>
               </div>
           </div>
    </body>

</html>

/*-------------------------------------------------------------------js部分-----------------------------------------------------------------------*/

var myModule=angular.module("MyModule",[]);
myModule.controller("MyCtrl",['$scope',function ($scope) {
    $scope.ctrlFlavor="Baiwei";
    $scope.eatctrlFlavor="糖醋里脊";
    $scope.resetDrflavor=function(){
        $scope.ctrlFlavor="百事可乐";
    }
    $scope.resetEtflavor=function(){
        $scope.eatctrlFlavor="脆皮蛋卷";
    }
    $scope.ggg = function(s) {
                alert("我成功绑定了父级作用域中的aaa函数!" + s);
            }
}]);
myModule.directive("drink",function(){
    return{
        restrict:'AE',
        scope:{
            f1:'@flavor'  //存储父元素中的flavor属性的值
        },
        template:"'new'+<div>{{f1}}</div>",
    }
});
myModule.directive("eat",function(){
    return{
        restrict:'ECMA',
        scope:{
            eatfood:'=eatfooda'  //存储父元素中eatfooda的引用 

   //  这里有个大坑
            // *****如果html属性中名称是驼峰法命名!!!在js里大写变小写!!!
            // *****html里是 - (eat-food)写法,则js里是驼峰法(eatFood)  

        },
        template:"<input type='text' ng-model='eatfood'>",
    }
});
myModule.directive("play",function(){
    return{
        restrict:'AE',
        scope:{
            child:'&aaa'  //存储父元素中的方法aaa
        },
        template:'<input type="button" ng-click="child()" value="点我哟~">',
    }
});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值