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
'programing' 카테고리의 다른 글
| ReactJS chrome 확장이 설치되었지만 표시되지 않음 (0) | 2023.03.13 |
|---|---|
| MongoDB 원자 "findOrCreate" : findOne, 존재하지 않는 경우 삽입하지만 업데이트하지 않습니다. (0) | 2023.03.13 |
| 경고: 검증DOMName(...): 하위 항목으로 표시할 수 없습니다. (0) | 2023.03.13 |
| 상대 경로와 함께 require 사용 (0) | 2023.03.13 |
| 반응에서 구성 요소 표시/숨기기JS (0) | 2023.03.13 |