Angular 终于没有在控制器中触发

Angular is finally not firing in controller

我在我的控制器中使用 angular 工厂来 运行,但是我的 finally 在控制器中并不有趣,它确实 运行下面的factory是代码:factory-

var createProfile = function (profile) {
    var deferred = $q.defer();

    $http.post("localhost/profile", profile)
        .success(function(data, status){
            deferred.resolve(data);
        })
        .error(function(error, status){
            $rootScope.error = sitesettings.parseErrors(error);              
        })
        .finally(function(){
            console.log('hello'); // **this message logs**
        });

    return deferred.promise;
};

在我的控制器中我有这个:

profileFactory.createProfile (profile)
    .then(function (data) {
        // **works if successful**

    })
    .finally(function () {
         console.log('fin'); // **this never fires, successfully or on an error**
    });

我想我可以像 profileFactory.createProfile (profile, myObject) 和 return 那样将我的对象传递到 profileFactory 中,但这似乎违反直觉。

有人可以请指教。谢谢。

亲切的问候

这是因为您要返回一个不同的承诺,您从未手动解决过。如果你只是 return $http.post(//etc.) 它应该可以正常工作。

编辑:

我可能很快就会联系上。我错过了你在成功中的决心。但这似乎没有必要。就这样

return $http.post("localhost/profile", profile);

并让您的控制器附加成功、错误和最终处理。