我无法得出一个合理的答案,为什么我不能在$ http.success()方法中调用$ broadcast。没有错误,$ broadcast在$ http.success()之外工作。侦听器位于angular-schema-form-upload的修改版本found here
上这是一个简化版本。如何从$ http的成功方法中触发监听器?
var app = angular.module('plunker', []).factory('projects',['$http', '$rootScope',function($http, $rootScope){
var service = {items:[], create: function(project){
return $http.post('/myrails/api/project', project).success(function(data){
service.items.push(data);
$rootScope.$broadcast('schemaFormFileUploadSubmit', {project_id: data.id});//this never works
});
}};
return service;
}]);
app.controller('MainCtrl', function($scope) {
$scope.name = 'World';
});