I am new to Angular.js and trying to get get routing working but in my app the second bellow route does not call the listController so I am not getting back data.
I have been through many working examples but cannot seem to work out why this is not working in my app? I get the template back /Categories/SixGrid but as mentioned the controller seem to not being called. Is there something obvious I am not doing wrong? Or can anyone share their knowledge on why this may not be working?
Updated code:
angular.module('App', ['App.Controller']).
config(['$routeProvider', function ($routeProvider) {
$routeProvider.when('/', { templateUrl: '/Home/Splash' });
$routeProvider.when('/Categories/List/:slug', { templateUrl: '/Categories/SixGrid', controller:'listController' });
}]);
angular.module('App.Controller', [])
.controller("listController", function ($scope, $http) {
$http.get('../../api/cat/' + $routeParams.slug).success(function (data) {
$scope.products = data;
});
});
Categories/Listwhile your route specifies that the template is to be found atCategories/SixGrid. How come? Also, you have an extraneous comma in your second route. Plus, your../../path is a bit uncommon for API call, although that shouldn't cause an error.Categories/SixGridis the correct template that comes back. Also removed the comma. The Api route is not currently ideal but am still in the early stages of dev