今天碰到的angular 中的一个小坑
2015-04-06 20:45
260 查看
最近在自个儿研究angular,在写一个demo的时候总是有问题,最后发现居然是大小写的问题,卧槽 特tm的坑爹了,代码如下:
修改后的代码如下:
切记,directive中的这个属性不能大写,注意标记为红色的单词!
<!DOCTYPE html> <html lang="en" ng-app="myApp"> <head> <meta charset="UTF-8"> <title>Document</title> <link rel="stylesheet" href="/css/bootstrap-3.0.0/css/bootstrap.css"> </head> <body> <div ng-controller="Demo_Ctr"> <!-- {{loveDrink}} <br/> --> <drinking showLove="ShownInfo(name)"></drinking> <drinking showLove="ShownInfo(name)"></drinking> <drinking showLove="ShownInfo(name)"></drinking> </div> <script src="/framework/angular-1.3.0.14/angular.js"></script> <script src="/scopeAnd.js"></script> </body> </html>
var myApp=angular.module('myApp',[]); myApp.controller('Demo_Ctr',['$scope',function($scope){ $scope.ShownInfo=function(name){ console.log("Hello "+name); } }]); myApp.directive('drinking',function(){ return { restrict:'AE', scope:{ showLove:'&' }, template:'<input type="text" ng-model="userName" /><br/>'+ '<button class="btn btn-default" ng-click="showLove({name:userName})">Show</button><br/>' } });
修改后的代码如下:
<!DOCTYPE html> <html lang="en" ng-app="myApp"> <head> <meta charset="UTF-8"> <title>Document</title> <link rel="stylesheet" href="/css/bootstrap-3.0.0/css/bootstrap.css"> </head> <body> <div ng-controller="Demo_Ctr"> <!-- {{loveDrink}} <br/> --> <drinking showLove="ShownInfo(name)"></drinking> <drinking showLove="ShownInfo(name)"></drinking> <drinking showLove="ShownInfo(name)"></drinking> </div> <script src="/framework/angular-1.3.0.14/angular.js"></script> <script src="/scopeAnd.js"></script> </body> </html>
var myApp=angular.module('myApp',[]); myApp.controller('Demo_Ctr',['$scope',function($scope){ $scope.ShownInfo=function(name){ console.log("Hello "+name); } }]); myApp.directive('drinking',function(){ return { restrict:'AE', scope:{ showlove:'&' }, template:'<input type="text" ng-model="userName" /><br/>'+ '<button class="btn btn-default" ng-click="showlove({name:userName})">Show</button><br/>' } });
切记,directive中的这个属性不能大写,注意标记为红色的单词!
相关文章推荐
- 今天在做rss解析的时候碰到一个奇怪的难题
- 今天碰到一个用7000+招php的人
- 今天碰到一个jQuery的问题没想明白
- 今天去面试碰到到一个问题
- 今天碰到一个很奇怪的问题,关于存储过程,留下以后用
- 今天不小心碰到一个变态英语句子,呵呵,强!
- 今天在bctc碰到一个韩国姑娘,皮肤好好,还碰到一个跟俺一样中午刷牙的姑娘。
- 在许多的面试题中会碰到行列转,今天又来一个行列转换,
- 今天在用c语言写一个栈,碰到不少问题,感觉到自己基础还是蛮差劲的,现在拿出来分享分享
- 今天碰到一个神经病,留念,以后少惹这种人!
- 今天碰到一个陌生的命令tracert,查了一篇文章来看
- 今天碰到了一个很诡异的题,Alphacode (zoj 2202)
- 今天碰到一个listener的问题,记录一下
- 今天碰到一个问题,在网上查了一下,发现有人碰到。转一下
- 今天碰到的一个极其愚蠢的错误
- 今天碰到一个强数据类型集的问题,不知道大家怎么解决呢????
- 今天用Visual C#为客户做一个数据下载分析系统,碰到一个问题 未能启用约束。一行或多行中包含违反非空、唯一或外键约束的值。
- 今天碰到了一个我非常佩服的售票员
- 今天碰到IE的一个问题, 两个IFRAME的问题
- 今天碰到一个poi解析excel文件的时候报错, 后来发现是这个excel文件单元格里面有公式。删除公式问题解决!