簡體   English   中英

如何解決angular [$ injector:unpr]未知提供程序錯誤?

[英]How to solve angular [$injector:unpr] Unknown provider error?

我正在嘗試為wordpress FreshlyPress Api開發一個使用角度,離子,科爾多瓦的簡單混合應用程序。這是我的文件,

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)

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

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

在我看來,您在第一本log中缺少$

它應該是$log而不是在以下行中log -

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

角度注射器無法找到log模塊,因此無法找到logprovider錯誤。 正確的模塊是$log

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM