我已经按照教程阅读了文档,但不明白我做错了什么。我总是得到.这是我所拥有的
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<title></title>
<script type="text/javascript" src="bower_components/angular/angular.js"></script>
<script type="text/javascript" src="directives/communicate.js"></script>
<script type="text/javascript">
var app = angular.module('myApp', []);
app.controller('abc', function($scope) {
});
app.directive('abd', function() {
return {
restrict: 'AE',
controller: function($scope) {
$scope.tab = [];
console.log('hello')
this.tab = function() {
$scope.tab.push('test');
}
}
}
});
app.directive('def', function() {
return {
require: 'abc',
link: function(scope, element, attrs, abcCtrl) {
console.log(abcCtrl.tab);
}
}
});
</script>
</head>
<body>
{{ 1 + 1 }}
<div def abc></div>
</body>
</html>
最后,我总是得到错误:找不到指令"def"要求的[$compile:ctreq]控制器"abc"。怎么来了?
知道了!这是一个错别字:(
app.directive('abd', function() {
...
应该是
app.directive('abc', function() {
...