AngularJS實現自訂指令與控制器資料互動的方法樣本,angularjs樣本
本文執行個體講述了AngularJS實現自訂指令與控制器資料互動的方法。分享給大家供大家參考,具體如下:
<!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>