码迷,mamicode.com
首页 > Web开发 > 详细

AngularJS: 自定义指令与控制器数据交互

时间:2015-04-15 09:28:07      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:

<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <title>AngularJS自定义指令与控制器数据交互</title>
<!--        <script src="http://cdn.bootcss.com/angular.js/1.3.15/angular.js"></script>-->
        <script src="../../lib/angular/angular.js"></script>
        <script>

        angular.module(‘yyApp‘, [])
        .controller(‘yyHelloController‘, function($scope){
            $scope.data = {
                name: ‘张三‘
            }
        })
        .controller(‘yyHelloController2‘, function($scope){
            $scope.data = {
                name: ‘李四‘
            }
        })
        .directive(‘yyHello‘, function(){
            return{
                restrict: ‘AE‘,
                replace: true,
                template: ‘<div name="{{data.name}}">你好,{{data.name}}</div>‘
            };
        });
            
        </script>
    </head>
    <body ng-app=‘yyApp‘>
        <yy-hello ng-controller=‘yyHelloController‘></yy-hello>
        <div ng-controller=‘yyHelloController2‘>
            <input type="text" ng-model=‘data.name‘>
            <yy-hello></yy-hello>
        </div>
    </body>
</html>

 

AngularJS: 自定义指令与控制器数据交互

标签:

原文地址:http://www.cnblogs.com/yaoyu126/p/4427550.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!