我正在尝试打开对话框,这些对话框有自己的控制器,通过事件打开它们。我现在的问题是,我总是得到
无法读取未定义的属性$emit",因为由于某种原因 我的$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"
});
});
}
}
}]);
试试这个
.directive("opendialog", ["$rootScope", function ($rootScope) {
return {
link: function (scope, element, attributes) {
element.bind("click", function (event) {
var dialogId = $(element).attr("id");
$rootScope.$emit(dialogId, {command: "open"});
});
}
}
}]);