从$ http.success()调用angular $ broadcast

时间:2016-12-08 15:55:06

标签: javascript angularjs http broadcast angular-schema-form

我无法得出一个合理的答案,为什么我不能在$ 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';
});

0 个答案:

没有答案