Angularjs 错误未知的提供者 [英] Angularjs error Unknown provider

查看:27
本文介绍了Angularjs 错误未知的提供者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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>

这是指令...

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值的服务部分

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

推荐答案

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

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=预览

这篇关于Angularjs 错误未知的提供者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆