Angularjs 那么如何使用角JS函数呢?

Angularjs 那么如何使用角JS函数呢?,angularjs,Angularjs,在将Then与函数一起使用后,我遇到了一个错误“TypeError:无法读取未定义的属性'Then'”您不能使用该函数,而是 app.controller('controller_name', function ($scope, $location, $auth, toastr, $http, CONFIG, $stateParams, $uibModal, $q, localStorageService, $anchorScroll, roundProgressService, $sce, c

在将Then与函数一起使用后,我遇到了一个错误“TypeError:无法读取未定义的属性'Then'”

您不能使用该函数,而是

app.controller('controller_name', function ($scope, $location, $auth, toastr, $http, CONFIG, $stateParams, $uibModal, $q, localStorageService, $anchorScroll, roundProgressService, $sce, calendarConfig, moment, $window, $rootScope) {

    $scope.a1(a, b, c, d, e).then(function(data){
        if (data.status == "OK") {
            angular.extend($scope.pets_list, response.data['pets_list']);
        }
    });

    $scope.a1 = function(a, b, c, d, e){
        $http({
            method: 'POST',
            url: 'url',
            data: {a: a, a: b},
            headers: {'Content-Type': 'application/x-www-form-urlencoded'}
        }).success(function (response) {
            return response.data;
        });
    };
});

你应该看看你的控制台。Javascript使用提升,因此您可以在调用函数后定义它们

吊装示例

函数foo(){
myFunc();
函数myFunc(){
console.log('foo');
}
}

foo()scope.get = function(a, b, c, d, e) { var defered = $q.defer(); $http.post('some_url', {a: a, a: b}).success(function(response){ defered.resolve(response); }).error(function(response){ defered.reject(response); }); return defered.promise; }; }; var promise = scope.get(a, b, c, d, e); promise.then(function(response){ console.log(response); },function(error){ console.log(error); });