programing

Angular JS, 해결 및 알 수 없는 공급자

starjava 2023. 3. 3. 16:48
반응형

Angular JS, 해결 및 알 수 없는 공급자

내게는 결단력 있는 두 가지 경로가 있다.다음과 같이 진행됩니다.

.when('/foos', {
templateUrl: 'views/foos.html',
controller: 'FoosCtrl',
resolve: {
    foo_list: ['$q', '$route', '$timeout', '$location', 'Foos', function($q, $route, $timeout, $location, Foos) {
        // postpone the execution
        var deferred_foo = $q.defer()

        Foos.getFoos({token:session_uid}, successCb)

        function successCb(list) {
            if(list['status'] === 200) {
                deferred_foo.resolve(list)
            }
            else {
                alert('Crashcrashcrash')
                deferred_foo.reject("Something just wasn't right")
                //$location.path('maintenance')
            }
        }
        return deferred_foo.promise
        }]
    }
})
.when('/r/:type/:bar_id', {
    templateUrl: 'views/bar.html',
    controller: 'BarsCtrl',
    resolve: {
        bar: ['$q', '$route', '$timeout', '$location', 'Bars', function($q, $route, $timeout, $location, Bars) {
            // postpone the execution
            var deferred = $q.defer()

            Bars.getBar({type: bar_type}, successCb)    

            function successCb(result) {
                if(result['status'] === 200) {
                    deferred.resolve(result)    
                }
                else {
                    alert('Crashcrashcrash')
                    deferred.reject("Something just wasn't right")
                    $location.path('foos')
                }

                return deferred.promise
                }]
            }
        })

그리고 두 개의 컨트롤러가 다음과 같이 작동합니다.

 App.controller('FoosCtrl', ['$scope', '$location', 'Foos', 'foo_list', function($scope, $location, Foos, foo_list) {...}

 App.controller('BarsCtrl', ['$scope', '$routeParams', '$location', 'Bars', 'bar', 'sharedService', function($scope, $routeParams, $location, Bars, bar, sharedService) {...}

누가 왜 바는 일하는데 푸는 나한테Error: Unknown provider: foo_listProvider <- foo_list교환을 시도했습니다.foo_list캐싱이 뭔가를 했지만 도움이 되지 않았을 때를 대비해서 이름을 바꿨어요

그래서, 이 질문은 놀랍게도 제가 방금 Angular IRC 채널에서 알게 된 것과 비슷했습니다.혹시 컨트롤러를 셋업하고 있는 건 아닐까요?ng-controller? 나는 다음을 가지고 있었다:

    <div ng-controller="myCtrl">

...언제 삭제해야 하는지:

    <div>

...라우터 상의 해결책으로 컨트롤러를 셋업하고 있었기 때문입니다.그게 바로 내가 하고 있던 일이었고 그것이 바로 이 문제를 야기하고 있었다.자세한 내용은 이쪽:

https://stackoverflow.com/a/18305423/1306982

foo_list <- 스크립트태그의 html 페이지에 js 파일이 로드되어 있습니까?팩토리/서비스/컨트롤러 포함을 잊어버리고 인덱스/앱html 페이지의 스크립트태그에 포함시키는 것을 잊어버렸을 경우(또는 shims가 필요했을 경우)일 수 있습니다.

네, 방금 코멘트를 보고 여기서 답을 확장했습니다.왜냐하면 여기서 하는 게 더 쉬우니까요.

컨트롤러를 선언하는 코드는 다음과 같습니다.

App.controller('FoosCtrl', 
   ['$scope', '$location', 'Foos', /* comment out foo_list here*/ 
    function($scope, $location, Foos, foo_list /* this remains */) {
  ...
}

루트가 변경되고 있을 때, 「sui」에 기재되어 있는 것은, ui-sui에 의해서 해결됩니다.그러나 FoosCtrl을 선언하는 장소에서는 실제로 FoosCtrl을 해결할 공급자가 없습니다.

한 번 해봐 저번 주에 비슷한 사건이 있었어

방금 전에 비슷한 문제가 발생했는데, 이 문제는 컨트롤러에 의존관계로서 resolve-variables를 추가했지만 응답기능을 설정하지 않았기 때문입니다.$stateProvider.state()아직.

해결 함수를 추가하면 누락된 종속성이 수정되었습니다.
(이유는 아직 잘 모르겠습니다.누구라도 코멘트로 그의 지식을 공유해 주셨으면 합니다.

언급URL : https://stackoverflow.com/questions/14846466/angularjs-resolve-and-unknown-provider

반응형