如何解决angular[$injector:unp]未知的提供程序错误
How to solve angular [$injector:unpr] Unknown provider error?
我正在尝试使用angular、ionic、cordova为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)
它应该是$log
,而不是以下行中的log
-
App.service("FreshlyPressed",["$http", "$log", FreshlyPressed]);
角度注入器无法找到log
模块,因此logprovider
错误。正确的模块是$log
App.service("FreshlyPressed",["$http", "log", FreshlyPressed]);
App.controller("AppCtrl" ,["$scope" , "FreshlyPressed", "$log" , AppCtrl]);
在我看来,第一个log
中缺少了一个$
。
相关文章:
- 为什么我得到错误:$injector:unp未知提供程序
- AngularJS错误:$injector:unp未知提供程序-$modalInstanceProvider
- Angular小部件中的Angular Grid返回错误:[$injector:unp]未知提供程序:
- 错误:$injector:unp未知提供者:未知提供者:bProvider<-b
- angular.js:13294错误:[$injector:unp]未知提供程序:cityResourceProvide
- ionic.bundle.js:25642错误:[$injector:unp]未知提供程序:$cordovaGeoloc
- 未能实例化模块[$injector:unp]未知提供程序:$routeProvider
- 错误:[$injector:unp]未知提供程序:Learning AngularJS可能使用一两个指针
- 未知错误:javascript错误:[$injector:unp]未知提供程序
- 错误:$injector:unp未知提供程序角度
- 错误:[$injector:unp]未知提供程序:RequestsServiceProvider<-请求服务htt
- 错误:[$injector:unp]在控制器中注入routeprovider服务时,jasmine测试中的提供程序未知
- 如何解决angular[$injector:unp]未知的提供程序错误
- 未捕获错误:[$injector:unp]未知提供程序:$localstorageProvider<-$本地存储
- 定义自定义提供程序和$injector:unp未知提供程序
- Angularjs文件上传:错误:[$injector:unp]未知提供程序:$uploadProvider<-$
- 错误:[$injector:unp]未知提供程序:modalInstanceProvider<-模式实例<-
- AngularJS$injector:unp未知提供程序错误
- 错误:[$injector:unp]未知提供程序:AuthServiceProvider角度服务
- 错误:$injector:unp AngularJS中的未知提供程序