我希望在完成角度$ http.post后更新我的控制器状态。我当前向控制器广播模块数据的状态已经改变并且导致控制器自己刷新。但是,我在实施方面遇到了问题。
postModule:
angular.module('commandPoster',[]).
service('commandPosterService', function($http) {
this.postCommand(command, devMode, callback) {
var path = "/client_api/command";
if(devMode) {
path = "/app_dev.php" + path;
}
$http.post(path, "commands=" + JSON.stringify(command), { headers: {'Content-Type':'application/x-www-form-urlencoded'} }).
success(function() {
if(callback) {
console.log("callback");
callback();
}
});
}
});
的AppModule:
angular.module('fittingApp', ['$strap.directives', 'commandPoster'])
.service('fittingDataService', ['$rootScope', 'commandPosterService',
function ($rootScope, poster) {
function broadcastStateChange (msg) {
msg = msg | "no msg";
console.log("updating: " + msg);
$rootScope.$broadcast('stateChange');
}
this.postCommand = function (command, devMode) {
poster.postCommand(command, devMode, broadcastStateChange);
};
});
编辑:
好像它没有进入成功处理程序。但我觉得应该这样。我在测试中返回了一个带有$ httpBackend的响应。