각도 [$injector:unpr] 알 수 없는 공급자 오류를 해결하는 방법? (How to solve angular [$injector:unpr] Unknown provider error?)


문제 설명

각도 [$injector:unpr] 알 수 없는 공급자 오류를 해결하는 방법? (How to solve angular [$injector:unpr] Unknown provider error?)

저는 FreshlyPress Api라는 wordpress에 대해 angular, ionic, cordova를 사용하여 간단한 하이브리드 앱을 개발하려고 합니다. 이것은 내 파일입니다.

app.js

var App = angular.module("SampleApp", ["ionic"]);

App.service("FreshlyPressed",["$http", "log", FreshlyPressed]);

App.controller("AppCtrl" ,["$scope" , "FreshlyPressed", "$log" , AppCtrl]);

function AppCtrl($scope, FreshlyPressed, $log){
    $scope.posts = [];
    $scope.refresh = function(){
        FreshlyPressed.getBlogs($scope);
    }
} 

function FreshlyPressed($http, $log){
    this.getBlogs =function($scope){
        $http.jsonp("https://public‑api.wordpress.com/rest/v1.1/freshly‑pressed?callback=JSON_CALLBACK")
        .success(function(result){
            $scope.posts=resul.posts;
        });
    };
}

index.html

<!DOCTYPE html>
<html lang="en" data‑ng‑app="SampleApp">
    <head>
        <meta charset="utf‑8">
        <title>Freshly Fressed</title>

        <!‑‑‑Ionic Libs‑‑>
        <link rel="stylesheet" href="lib/ionic/css/ionic.css">
        <script src="lib/ionic/js/ionic.bundle.js"></script>

        <!‑‑Myapp‑‑>

        <link rel="stylesheet" href="css/style.css">
        <script src="js/app.js"></script>

    </head>
    <body data‑ng‑controller="AppCtrl">
        <ion‑header‑bar class="bar‑balanced">
            <h1 class="title">Freshly Pressed</h1>
            <button class="button" data‑ng‑click="refresh()">
            <i class="icon ion‑refresh"></i>

            </button>
        </ion‑header‑bar>
        <ion‑content>
            <div class="card list" data‑ng‑repeat="p in posts">
                <div class="item item‑avatar‑left">
                    <img data‑ng‑src="{{ p.author.avatart_URL }}" alt="">
                    <h2>{{ p.author.nice_name }}</h2>
                    <p><a href="{{ p.author.URL }}">{{ p.author.URL }}</a></p>
                </div>
                <div class="item item‑body">
                    <h1>{{ p.title }}</h1>
                    {{ p.content }}
                </div>
            </div>

        </ion‑content>

    </body>
</html>

하지만 이 코드를 실행할 때 다음과 같은 오류가 발생합니다.

Error: [$injector:unpr] Unknown provider: logProvider <‑ log <‑ FreshlyPressed
http://errors.angularjs.org/1.4.3/$injector/unpr?p0=logProvider%20%3C‑%20log%20%3C‑%20FreshlyPressed
    at ionic.bundle.js:8900
    at ionic.bundle.js:13094
    at Object.getService [as get] (ionic.bundle.js:13241)
    at ionic.bundle.js:13099
    at getService (ionic.bundle.js:13241)
    at invoke (ionic.bundle.js:13273)
    at Object.instantiate (ionic.bundle.js:13290)
    at Object.<anonymous> (ionic.bundle.js:13151)
    at Object.invoke (ionic.bundle.js:13282)
    at Object.enforcedReturnValue [as $get] (ionic.bundle.js:13135)

참조 솔루션

방법 1:

App.service("FreshlyPressed",["$http", "log", FreshlyPressed]);

App.controller("AppCtrl" ,["$scope" , "FreshlyPressed", "$log" , AppCtrl]);

Seems to me you are missing an $ from the first log.

방법 2:

It should be $log instead of log in following line‑

App.service("FreshlyPressed",["$http", "$log", FreshlyPressed]);

Angular injector is not able to find the log module and therefore the logprovider error. Correct module is $log

(by prashna prashnaÁgoston SzékelyChandan)

참조 문서

  1. How to solve angular [$injector:unpr] Unknown provider error? (CC BY‑SA 2.5/3.0/4.0)

#ionic #angularjs #wordpress #javascript #cordova






관련 질문

Cordova - OS 업그레이드 후 iOS/Android 모두에서 앱 충돌 (Cordova - app crashes on both iOS/Android after an OS upgrade)

모바일용 HTML 5의 특정 영역에 링크가 있는 이미지 (Image with links in certain areas in HTML 5 for mobile)

Play 스토어에서 오류 발생 - "이 앱은 모든 기기와 호환되지 않습니다." (Getting error from play store - “This app is incompatible with all of your devices.”)

div의 오른쪽 하단에 이온 버튼 정렬 (Align an ionic button at the bottom right of a div)

새로운 Xcode 프로비저닝 정책 및 Ionic Framework (New Xcode provisioning policy and Ionic Framework)

각도 [$injector:unpr] 알 수 없는 공급자 오류를 해결하는 방법? (How to solve angular [$injector:unpr] Unknown provider error?)

ionic, 팝오버 범위에 범위 변수 전달 (ionic, pass scope variable to popover scope)

Angular: 2필드 데이터 바인딩 문제 (Angular: issue with two-field data binding)

ionic 2에서 ion-title의 글꼴 색상 변경 (Change font color of ion-title in ionic 2)

PhoneGap 빌드가 내 모든 파일을 업데이트하지 않습니다. (PhoneGap build is not updating all of my files)

Ionic 빌드 Android를 수행하는 동안 오류가 발생했습니다. (Error while doing Ionic build android)

$ionicHistory.backView() stateParams 변경 후 돌아가기 (Going back after changing stateParams of $ionicHistory.backView())







코멘트