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>
更多关于AngularJS相关内容感兴趣的读者可查看本站专题:《AngularJS指令操作技巧总结》、《AngularJS入门与进阶教程》及《AngularJS MVC架构总结》
希望本文所述对大家AngularJS程序设计有所帮助。
相关推荐
Frankywls 2019-10-19
QiaoranC 2020-09-25
颤抖吧腿子 2020-09-04
liduote 2020-06-16
阿斌Elements 2020-06-11
xxuncle 2020-06-05
ChinaGuanq 2020-06-05
wanghongsha 2020-03-26
csm0 2020-03-05
shyoushine 2020-02-25
electronvolt 2020-02-12
jsonwoo 2020-01-20
ZadarrienChina 2020-01-07
wwwxuewen 2020-01-04
dynsxyc 2020-01-03
liangjielaoshi 2019-12-27
bowean 2019-12-27
wwwxuewen 2019-12-25
liwusen 2019-12-16