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

AngularJS的指令用法

时间:2015-12-06 13:06:07      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:

scope的绑定策略:

@ :把当前属性作为字符串传递,你还可以绑定来自外层scope的值,在属性值中插入 {{}}即可

示例代码:

scopeAt.html

<!doctype html>
<html ng-app="MyModule">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="css/bootstrap-3.0.0/css/bootstrap.css">
</head>
<body>
<div ng-controller="MyCtrl">
<drink flavor="{{ctrlFlavor}}"></drink>
<fruit food="{{ctrlFood}}"></fruit>
</div>
</body>
<script src="framework/angular-1.3.0.14/angular.js"></script>
<script src="ScopeAt.js"></script>
</html>

scopeAt.js

var myModule = angular.module("MyModule", []);
myModule.controller(‘MyCtrl‘, [‘$scope‘, function($scope){
$scope.ctrlFlavor="百威";
$scope.ctrlFood="香蕉";
}])
myModule.directive("drink", function() {
return {
restrict:‘AE‘,
scope:{
flavor:‘@‘
},
template:"<div>{{flavor}}</div>"
// ,
// link:function(scope,element,attrs){
// scope.flavor=attrs.flavor;
// }
}
});

myModule.directive("food", function() {
return {
restrict:‘AE‘,
scope:{
food:‘@‘
},
template:"<div>{{food}}</div>"

}
});

 

AngularJS的指令用法

标签:

原文地址:http://www.cnblogs.com/klsw/p/5023316.html

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