0

I have following PhoneCat tutorial combined with an angular seed project. Now i come into the problem, i can't get routing to work / load, no errors occur and everything seems fine. Can't even seem to get, the basic redirect to work. I'm lost what to do.

Here is my app.js where i think the error is

'use strict';

var elgrossisten = angular.module('elgrossisten', [
  'ngRoute',
  'elgrossistenControllers'
]);

elgrossisten.config(['$routeProvider',
  function($routeProvider) {
    $routeProvider.
      when('/search', {
        templateUrl: 'partials/elnrlist.html',
        controller: 'SearchElNrCtrl'
      }).
      otherwise({
        redirectTo: '/search'
      });
  }]);

controller

var elgrossistenControllers = angular.module('elgrossisten', []);

elgrossistenControllers.controller('SearchElNrCtrl', function ($scope) {
  $scope.elnrs = [
    {'elnr': '10150135',
     'avgprice': '18.75',
     'lastupdated': '01-01-2014'},
    {'elnr': '10170135',
     'avgprice': '18.75',
     'lastupdated': '01-01-2014'},
    {'elnr': '10110135',
     'avgprice': '18.75',
     'lastupdated': '01-01-2014'}
  ];
});

And how i load my scripts.

<script src="../bower_components/angular/angular.js"></script>
<script src="../bower_components/angular-route/angular-route.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>
3
  • Give an example of what url you are going to, what you expect to see and what you actually see. Commented Apr 6, 2014 at 20:49
  • elgrossisten/app/#/search/ should hopefully redirect to my controller and view while elgrossisten/app/ should redirect me to #/search Commented Apr 6, 2014 at 20:51
  • sloppy naming was the reason angular.module('elgrossisten', [ 'ngRoute', 'elgrossistenControllers' ]); should have been angular.module('elgrossistenControllers', [ 'ngRoute', 'elgrossistenControllers' ]); Commented Apr 6, 2014 at 21:06

1 Answer 1

1

Your elgrossisten module depends on two others:

angular.module('elgrossisten', [
   'ngRoute',
   'elgrossistenControllers'
]);

Those two modules need to be defined before you instantiate your elgrossisten module. Maybe try loading your scripts this way?

<script src="../bower_components/angular/angular.js"></script>
<script src="../bower_components/angular-route/angular-route.js"></script>
<script src="js/controllers.js"></script>
<script src="js/app.js"></script>
<script src="js/services.js"></script>
<script src="js/filters.js"></script>
<script src="js/directives.js"></script>

You need to include your dependant modules before you load your app js (as this one depends on others). Although I don't really understand why no error is showing for you. If you provide some more information, or a plnkr, I could help you out a bit more.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.