Angularjs错误未知的供应商 [英] Angularjs error Unknown provider
问题描述
我试图显示配置的值作者
和版本
的角度值服务于HTML page.Version code显示正常,但不是作者的名字
下面是HTML code
<!DOCTYPE HTML>
< HTML LANG =ENNG-应用=对myApp>
< HEAD>
<间的charset =UTF-8>
<标题>我AngularJS应用< /标题>
<链接rel =stylesheet属性HREF =CSS / app.css/>
< /头>
<身体GT;
< UL类=菜单>
<立GT;< A HREF =#/视图1>厂景< / A>< /李>
<立GT;< A HREF =#/视图2>&视图2 LT; / A>< /李>
< / UL> < DIV NG-视图>< / DIV> < DIV>角种子应用:V<跨度的应用程序版本>< / SPAN>< / DIV>
< DIV>作者为:或其可跨应用程序的作者和GT;< / SPAN>< / DIV>
&所述; SCRIPT SRC =LIB /角度/ angular.js>&下; /脚本>
<脚本SRC =JS / app.js>< / SCRIPT>
<脚本SRC =JS / services.js>< / SCRIPT>
<脚本SRC =JS / controllers.js>< / SCRIPT>
<脚本SRC =JS / filters.js>< / SCRIPT>
<脚本SRC =JS / directives.js>< / SCRIPT>
< /身体GT;
< / HTML>
下面是指令...
angular.module('myApp.directives',[])。
指令(appVersion',['版本',函数(版本){
返回功能(范围,榆树,ATTRS){
elm.text(版本);
};
}])
.directive('appAuthor',['作家',函数(作者){
返回功能(范围,榆树,ATTRS){
elm.text(作者);
};
}]);
和这里的服务部分,其中作者
和版本
值配置
angular.module('myApp.services',[])。
值('版本','0.1')
.value的('作家','JIM');
我得到在开发者控制台的误差
错误:未知提供商:authorProvider< - 笔者< - appAuthorDirective
请确保您装载这些模块( myApp.services 的和的 myApp.directives 的)作为依赖你的主要应用模块,如:
angular.module('对myApp',['myApp.directives','myApp.services']);
plunker: http://plnkr.co/edit/wxuFx6qOMfbuwPq1HqeM?p=$p$pview
I'm trying to display the configured values author
and version
in angular value service in html page.Version code is displayed fine but not the author name
Here is the html code
<!doctype html>
<html lang="en" ng-app="myApp">
<head>
<meta charset="utf-8">
<title>My AngularJS App</title>
<link rel="stylesheet" href="css/app.css"/>
</head>
<body>
<ul class="menu">
<li><a href="#/view1">view1</a></li>
<li><a href="#/view2">view2</a></li>
</ul>
<div ng-view></div>
<div>Angular seed app: v<span app-version></span></div>
<div>Author is : <span app-author></span></div>
<script src="lib/angular/angular.js"></script>
<script src="js/app.js"></script>
<script src="js/services.js"></script>
<script src="js/controllers.js"></script>
<script src="js/filters.js"></script>
<script src="js/directives.js"></script>
</body>
</html>
Here is the directive...
angular.module('myApp.directives', []).
directive('appVersion', ['version', function(version) {
return function(scope, elm, attrs) {
elm.text(version);
};
}])
.directive('appAuthor', ['author', function(author) {
return function(scope, elm, attrs){
elm.text(author);
};
}]);
And here is the service portion where author
and version
values are configured
angular.module('myApp.services', []).
value('version', '0.1')
.value('author','JIM');
The error i'm getting in developer console is
Error: Unknown provider: authorProvider <- author <- appAuthorDirective
Make sure you are loading those modules (myApp.services and myApp.directives) as dependencies of your main app module, like this:
angular.module('myApp', ['myApp.directives', 'myApp.services']);
plunker: http://plnkr.co/edit/wxuFx6qOMfbuwPq1HqeM?p=preview
这篇关于Angularjs错误未知的供应商的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!