Angularjs 语法:如何在服务中侦听或发出$emit?
我想在rootScope上侦听'MyCommittedEvent',但此代码有问题:Angularjs 语法:如何在服务中侦听或发出$emit?,angularjs,Angularjs,我想在rootScope上侦听'MyCommittedEvent',但此代码有问题: app.service('MyService',function($rootScope){ $rootScope.$on('myEmittedEvent', function(){ <===== error here // code goes here }); }); app.service('MyService',函数($rootScope
app.service('MyService',function($rootScope){
$rootScope.$on('myEmittedEvent', function(){ <===== error here
// code goes here
});
});
app.service('MyService',函数($rootScope){
$rootScope.$on('myEmittedEvent',function(){请重试
app.service('MyService',['$rootScope',function($rootScope){
$rootScope.$on('myEmittedEvent', function(){ <===== error here
// code goes here
});
return {};
}]);
app.service('MyService',['$rootScope',function($rootScope){
$rootScope.$on('myEmittedEvent',function(){看起来有效…唯一的
在app.service
-是app
声明的吗?这个代码之前有什么东西吗?我看到的只是一个额外的}
,看起来有效。尝试删除最后一个}
之后的分号。我的意思是app.service('MyService',function>(){};
你能在plunker中复制这个吗?你确定你复制/粘贴的代码片段正确吗?(我的意思是,我们应该找到一个语法错误,并且已经做了两次复制/粘贴错误。)听起来你可能在某处拼写错了函数
。。。