programing

AngularJS 오류.성공은 함수가 아닙니다.

kakaobank 2023. 3. 13. 20:37
반응형

AngularJS 오류.성공은 함수가 아닙니다.

컨트롤러의 기능을 처리하기 위해 공장을 구축했는데 컨트롤러가 다음 기능 중 하나에 오류를 반환합니다.

오류: Auth.getUser(...).성공은 함수 @http://localhost:8080/app/controllers/mainCtrl.js:10:1이 아닙니다.
...

여기서 무슨 일이 일어나고 있는지 모르겠는데, 다른 기능들은 잘 작동하는 것 같아요?

메인 컨트롤러:

angular.module('mainCtrl', [])
.controller('mainController', function($rootScope, $location, Auth) {
    var vm = this;
    vm.loggedIn = Auth.isLoggedIn();
    $rootScope.$on('$routeChangeStart', function() {
        vm.loggedIn = Auth.isLoggedIn();
        Auth.getUser()
            .success(function(data) {
                vm.user = data;
            });
    });
    vm.doLogin = function() {
        Auth.login(vm.loginData.username, vm.loginData.password)
            .success(function(data) {
                $location.path('/users');
            });
    };
});

$http 서비스 문서의 '사용 중지 알림'을 참조하십시오.

$http 레거시 약속 메서드성공과 오류는 폐지되었습니다.대신 standard then method를 사용합니다.

이러한 방법에 대한 자세한 내용은 $q에 대한 설명서를 참조하십시오.

여기 코드가 있습니다.

디프로세서 코드

$http(  
{  
    method: 'POST',  
    url: '/Home/CreateCustomer',   /*You URL to post*/
    data: $scope.cust   /*You data object/class to post*/
}).success(function (data, status, headers, config)  
{  

}).error(function (data, status, headers, config)  
{  

}); 

허가 코드 각 $http 문서

$http(
    {
       method: 'POST',
       url: '/Home/CreateCustomer',  /*You URL to post*/
       data: $scope.cust  /*You data object/class to post*/
    }).then(function successCallback(response) {
       // this callback will be called asynchronously
       // when the response is available


    }, function errorCallback(response) {
       // called asynchronously if an error occurs
       // or server returns response with an error status.

});

다음을 사용하여 성공을 설치할 수 있습니다.

var personController = function ($scope, personService) {
    $scope.persons = personService.getAll().then(function (data) {
        $scope.persons = genericSuccess(data);
    });
    var genericSuccess=function(res) {
        return res.data;
    }
};

어쨌든 성공이 추천되지 않는 것은 좋은 일이다.난 개인적으로 화해한 적이 없어, 왜 물어보는 거야?

object.functionCall(parameters).success(functions (response){

if(response!=="failure")
do this-----
});

내 말은 어떤 성공이 실패에 대처하느냐는 거야대신 사용하시면 모든 논리가 이치에 맞기 시작할 것입니다.

성공 약속은 이제 폐지되었습니다.성공 대신 기능 사용

angular version 1.2.x . success angular version 1.6 . x . " 、 " . success is not function " (성공은 함수가 아닙니다)"라는 오류가 나타납니다.

솔루션은 다음과 같습니다. ".success"를 ".then"으로 바꿉니다.

언급URL : https://stackoverflow.com/questions/33531336/angularjs-error-success-is-not-a-function

반응형