1,link中的数据没办法和controller中的数据完成相互绑定
<html >
<head>
<meta charset="UTF-8">
<title>Bootstrap Modal and popover with Velocity.js animation</title>
<script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
<!-- <link rel="stylesheet" type="text/css" href="elfinderCtroller.js"> -->
</head>
<body>
<div ng-app = "app" ng-controller="elfinder" name = "mingzi">
Name: <input ng-model="mingzi">
<p>{{mingzi}}</p>
<texts names></texts>
</div>
<script>
var app = angular.module('app', []);
app.controller('elfinder',function($scope){
$scope.mingzi = "caa";
})
app.directive('texts', function(){
return{
restrict:'EC',
scope: {
name : "=",
},
// controller : 'elfinder',
link: function(scope) {
scope.name = 'fwt';
}
};
});
</script>
</body>
</html>
2
写法没对,改一下就好了:
参考文章:AngularJS内幕详解之 Directive