【发布时间】:2014-08-09 15:06:23
【问题描述】:
我有一个嵌套指令。我正在尝试访问父指令的范围(它是孤立的),但似乎无法使其工作。尝试将其注销到控制台时出现未定义的错误。
这是我正在努力工作的一个例子。
app.directive("myParentControl", function() {
return {
restrict: "A",
scope: {},
controller: function($scope) {
$scope.propertyOne = "PropertyOne"
},
link: function(scope, element) {
console.log(scope.propertyOne);
}
}
});
app.directive("myChildControl", function() {
return {
require: "^myParentControl",
link: function(scope, element, attrs, myParentControlCtrl) {
//Undefined
console.log(myparentControlCtrl.propertyOne);
//Not visible in scope inspector
myParentControlCtrl.newValue = "New Value";
}
}
})
【问题讨论】: