gpt4 book ai didi

javascript - Angularjs错误未知提供者

转载 作者:IT王子 更新时间:2023-10-29 03:16:33 26 4
gpt4 key购买 nike

我正在尝试在 html 页面的 Angular 值服务中显示配置值 authorversion。版本代码显示正常但不是作者姓名这是html代码

    <!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>

这是指令...

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);
};
}]);

这是配置authorversion 值的服务部分

    angular.module('myApp.services', []).
value('version', '0.1')
.value('author','JIM');

我在开发者控制台中得到的错误是

Error: Unknown provider: authorProvider <- author <- appAuthorDirective

最佳答案

确保将这些模块(myApp.servicesmyApp.directives)加载为主应用模块的依赖项,如下所示:

angular.module('myApp', ['myApp.directives', 'myApp.services']);

插件: http://plnkr.co/edit/wxuFx6qOMfbuwPq1HqeM?p=preview

关于javascript - Angularjs错误未知提供者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15244272/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com