我的指令如下
.directive('ticketingChat', function() {
return {
restrict: 'E',
templateUrl: '/Reply/ReplyScreen', //cshtml from MVC page
controller: 'TicketingChatController',
link: function (scope, el, attr) {
scope.writingTo = "Hey there!";
}
}
})
我认为这会创建它自己的范围,而“范围”将允许我访问它。
相反,ng-inspector告诉我:
“范围”实际上是根范围。如何强制指令创建自己的子范围? 如何从链接功能访问该范围?
答案 0 :(得分:1)
在指令定义对象中设置the invoice email was sent
将使AngularJS创建一个继承子范围。将scope: true
设置为对象将创建一个独立的子范围。
例如:
scope
有关.directive('ticketingChat', function() {
return {
restrict: 'E',
templateUrl: '/Reply/ReplyScreen',
controller: 'TicketingChatController',
scope: true,
link: function (scope, el, attr) {
scope.writingTo = "Hey there!"; // This will be set on the child scope because we have scope: true.
}
}
})
属性的详细信息,请参阅the docs。