<!DOCTYPE html>
<html lang="zh-cn" ng-app="myApp">
<head>
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
<meta http-equiv="x-ua-compatible" content="IE=edge">
<meta charset="utf-8">
<title></title>
</head>
<body>
<div ng-controller="listCtrl">
<input type="text" ng-model="t" />
<kid title="{{t}}" > //这个必须指定的,这里的title是指令里scope的@对应的,t就是控制域scope下的
<span>我的angularjs</span>
</kid>
</div>
<script src="js/angular.js"></script>
<script>
var myApp=angular.module('myApp',['ng']);
myApp.controller('listCtrl',function($scope){
$scope.logchore="motorola";
});
myApp.directive('kid',function(){
return {
'restrict':'E',
scope:{
title:"@"
},
template:'<div >{{title}}</div>'
}
});
</script>
</body>
</html>
转载于:https://www.cnblogs.com/dianzan/p/7284539.html