31

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
L42y
  • 972
  • 1
  • 9
  • 18
agasthyan
  • 725
  • 3
  • 8
  • 17
  • Even I was stuck in same issue, I fixed it yet I kept getting same issue. Note that `function getService(serviceName, caller) { if (cache.hasOwnProperty(serviceName))` After fixing issue **don't forget to do Ctrl+F5 to clear browser cache.** – vikky MCTS Feb 06 '17 at 15:03

2 Answers2

48

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

bmleite
  • 26,850
  • 4
  • 71
  • 46
  • Well i'm loading those modules.but if dats the problem then how could version number get displayed and author not – agasthyan Mar 06 '13 at 12:09
  • Can you provide a plunker or jsfiddle with a replica of the problem? It could be a typo or some kind of collision on service names. (As you can see, on the one I've provided it is working correctly) – bmleite Mar 06 '13 at 12:30
  • 1
    well i think u were i was missing to load some modules.Thanks dat helped :) – agasthyan Mar 06 '13 at 13:18
31

bmleite has the correct answer about including the module.

If that is correct in your situation, you should also ensure that you are not redefining the modules in multiple files.

Remember:

angular.module('ModuleName', [])   // creates a module.

angular.module('ModuleName')       // gets you a pre-existing module.

So if you are extending a existing module, remember not to overwrite when trying to fetch it.

Jukka Dahlbom
  • 1,740
  • 2
  • 16
  • 23
  • 1
    I had no idea that was the case. I was defining a variable and setting it equal to angular.module(...) after the angular-seed default ctrls, and was getting this same problem. Saved me much hair. – Kreychek Jul 04 '14 at 17:44
  • Excellent hint to search for `"angular.module('..', "` in a codebase to see where the module/'app' is created, thanks! – Dr1Ku Jan 07 '15 at 15:06
  • Wow! This is genius! – ATrubka Mar 30 '16 at 16:44