Angular dependency doesn't work

30 views
Skip to first unread message

Vincent Cueto

unread,
Oct 2, 2014, 7:52:35 PM10/2/14
to ang...@googlegroups.com
Hi all !! 

I am new with angular and i need your help to understand what's is my problem :)

I created a simple app.js like this one :

(function() {
  var app = angular.module('teamStats', []);

  app.directive("header", function() {
 return {
restrict: 'E',
templateUrl: "header.html"
 };
  });
  
  app.controller('TeamController', function(){
       
  });
  
})();

Here there is no dependency, i just get my header in index.html thanks to the code below and that is working !!! WOOT i am so happy !

<header></header>

Now i want tu put the directive calling my header in another file called : template.js

(function(){
    var app = angular.module('template-directives', []);

    app.directive("header", function() {
      return {
        restrict: 'E',
        templateUrl: "header.html"
      };
    });
})();


My app.js is now like this :

(function() {
  var app = angular.module('teamStats', ['template-directives']);
})();


My header doesn't appear in my index.html i don't understand why .. my dependency is not correctly set ? i forgot something ?

If someone can help ;) it would be really nice !
Thanks for all !!

Best regards,
CUETO Vincent

Eric Eslinger

unread,
Oct 2, 2014, 8:39:35 PM10/2/14
to ang...@googlegroups.com
Are both javascript files being loaded by index.html?

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Vincent Cueto

unread,
Oct 2, 2014, 8:43:49 PM10/2/14
to ang...@googlegroups.com
Yes i put both in my index like this :

<script src="js/app.js"></script>
<script src="js/template.js"></script>

Majid Burney

unread,
Oct 3, 2014, 1:37:23 PM10/3/14
to ang...@googlegroups.com
For one thing, neither of your revised js files include the TeamController definition any longer. If you’re actually referencing that controller, either in index.html or header.html, Angular will fail to bootstrap.

If that’s not the problem, you should post any errors you see in the developer console.
Reply all
Reply to author
Forward
0 new messages