我已经在一个元素上声明了两个指令:一个请求隔离范围,另一个请求继承范围。在这里看起来如何:
守则
var app = angular.module('app', []);
app.directive('mainDir', function () {
return {
restrict: 'A',
scope: {
title: '='
},
link: function(scope) {
scope.title = "A";
}
}
});
app.directive('subMainDir', function ($timeout) {
return {
restrict: 'A',
scope: true,
link: function (scope) {
scope.title = "A";
}
}
});
app.controller('mainCtrl', function ($scope) {
$scope.title = "Hi";
});
以下行可行:
<div sub-main-dir main-dir title="title"></div>
但是以下一行:
<div main-dir title="title" sub-main-dir></div>
提出错误提示:
angular1.2.0-rc.2.js:7861错误:[$ compile:multidir] Multiple 指令[mainDir,subMainDir]要求隔离范围:
为什么第一行有效但第二行有异常?