Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs $http.post之后的UI更新_Angularjs_Http Post_Controllers - Fatal编程技术网

Angularjs $http.post之后的UI更新

Angularjs $http.post之后的UI更新,angularjs,http-post,controllers,Angularjs,Http Post,Controllers,我想在使用完angular中的$http.post后更新控制器的状态。我当前向控制器广播模块数据的状态已更改,这会导致控制器刷新自身。但是,我在执行方面遇到了问题 后模块: angular.module('commandPoster',[]). service('commandPosterService', function($http) { this.postCommand(command, devMode, callback) { var p

我想在使用完angular中的$http.post后更新控制器的状态。我当前向控制器广播模块数据的状态已更改,这会导致控制器刷新自身。但是,我在执行方面遇到了问题

后模块:

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();
                    }
                });

        }
    });
应用模块:

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的响应。

尝试输入一个错误函数,看看是否捕获了某些内容……我想我已经找到了原因。我在帖子上循环,所以只有最后一篇帖子真正成功了。很好!几天前,我对$http方法的顺序调用遇到了一些问题,一些调用被错过了。。。无论如何,我已经更改了代码,只发出一个请求。我不知道这是否是你的情况,但很高兴知道=