<!doctype html>
<html ng-app='myApp'>
<head>
</head>
<body>
<script src="http://cdn.bootcss.com/angular.js/1.4.6/angular.js"></script>
<script src="https://cdn.bootcss.com/jquery/1.8.3/jquery.js"></script>
<div ng-controller="listCtrl" ng-app="myApp">
<input type="text" ng-model="color">
<!-- <span kid hd-color="color"></span> --> <!--@是单项数据绑定,hd-color="{{color}}"作用域隔离,在view中是以模板“{{}}”的形式;=双向绑定,hd-color="color",在view中直接以属性的形式出现-->
<div kid color="callback()"></div>
</div>
<script type="text/javascript">
var myApp=angular.module('myApp',[]);
myApp.controller('listCtrl',function($scope){
$scope.color="red";
$scope.callback=function(){
return 'a web developer !';
}
});
myApp.directive('kid',function(){
return {
restrict:'AE',
//template:'<div style="color:{{color}}">@符号的学习</div>' ,
template:'<h1>{{color()}}</h1>',
scope:{ /*color:"=hdColor"*//* "@hdColor" */color:'&'} //通过&属性名来调用控制器的函数
}
});
</script>
</div>
</body>
</html>