programing

AngularJs ReferenceError: $http가 정의되지 않았습니다.

golfzon 2023. 3. 10. 22:59
반응형

AngularJs ReferenceError: $http가 정의되지 않았습니다.

다음과 같은 각도 기능이 있습니다.

$scope.updateStatus = function(user) {    
    $http({
        url: user.update_path, 
        method: "POST",
        data: {user_id: user.id, draft: true}
    });
};

하지만 이 함수가 호출될 때마다 콘솔에 들어갑니다.누가 내가 여기서 뭘 잘못하고 있는지 이해시켜 줄 수 있나요?

아마 주사 안 맞았을 거예요$http서비스를 제공합니다.그것을 하는 방법에는 여러 가지가 있다.

DI에 관한 레퍼런스를 읽어주세요.그 후 매우 심플해집니다.

function MyController($scope, $http) {
   // ... your code
}

사용할 때도 같은 문제를 겪었습니다.

    myApp.controller('mainController', ['$scope', function($scope,) {
        //$http was not working in this
    }]);

위 코드를 아래와 같이 변경하였습니다.아래와 같이 $http(2회)를 포함해야 합니다.

 myApp.controller('mainController', ['$scope','$http', function($scope,$http) {
      //$http is working in this
 }]);

잘 되고 있어요.

Amit Garg의 답변을 완성하기 위해 Angular에 의존성을 주입하는 몇 가지 방법이 있습니다.JS.


를 사용하여 종속성을 추가할 수도 있습니다.

var MyController = function($scope, $http) {
  // ...
}
MyController.$inject = ['$scope', '$http'];

언급URL : https://stackoverflow.com/questions/13759120/angularjs-referenceerror-http-is-not-defined

반응형