我已经在一个元素上声明了两个指令:一个请求隔离范围,另一个请求继承范围。这里是:在同一元素上请求隔离作用域和继承作用域的两个指令
守则
angular.module("myApp", [])
.directive("myDirective", function() {
return {
restrict: "A",
scope: {
users: "="
},
templateUrl: "users-info.html",
link: function(scope) {
scope.title = "From My Directive";
}
}
})
.directive("otherDirective", function() {
return {
restrict: "A",
scope: true,
link: function(scope) {
scope.title = "From Other Directive";
}
};
})
.controller("AppController", function($scope) {
$scope.users = [
{name: "Anup Vasudeva", username: "anup_vasudeva"},
{name: "Ajay Sharma", username: "ajay_sharma"},
{name: "Vinay Kumar", username: "vinay_kumar"}
];
$scope.title = "Users Information";
});
和HTML
<div my-directive other-directive>{{title}}</div>
但AngularJS抛出错误提的网址:
http://docs.angularjs.org/error/$compile/multidir
但在描述的错误,我没有看到它指出请求隔离和继承范围的多个指令是不允许的。
**编辑** 这似乎很奇怪,当我使用角v1.2.0-rc.2
时,上述情况正常工作。即使它请求共享范围,otherDirective
也会获得一个隔离范围。但是这种情况在最新版本中不起作用。
Thanks @Nick。 otherDirective是否有可能拥有继承范围?我希望otherDirective能够访问“用户”模型 –
它具有继承范围。看到我更新的小提琴:[http://jsfiddle.net/24Pyg/1/](http://jsfiddle.net/24Pyg/1/)。其他Directive范围的标题来自其父控制器。从我看到的 – Nick
中,其他指令具有共享范围,而不是继承范围。纠正我,如果我错了。我关心的是为什么otherDirective在请求继承范围时出现错误。 –