【发布时间】:2018-12-26 20:20:28
【问题描述】:
我正在尝试打开具有自己的控制器的对话框,通过事件打开它们。 我现在的问题是,我总是得到 p>
无法读取属性 $emit of undefined`,因为某些原因 我的 $rootScope 未定义。
如何正确注入$rootScope?
我正在使用 Angular 1.6.7。
.directive("opendialog", [function($rootScope) {
return {
link: function(scope, element, attributes) {
element.bind("click", function(event) {
var dialogId = $(element).attr("id");
$rootScope.$emit(dialogId, {
command: "open"
});
});
}
}
}]);
【问题讨论】:
标签: angularjs angularjs-directive rootscope