angularjs - $routeProvider not working in angular -
this app.js
var cricketapp = angular.module('cricketapp', ['ngcookies']). config(['$routeprovider', function($routeprovider, $httpprovider, $cookies){ $routeprovider. when('/', { templateurl: '/partials/games-pending-entry.html', controller: homectrl }). when('game/:gameid',{ templateurl: 'partials/shortlist.html', controller: shortlistctrl }). otherwise({redirectto: '/'}); //$httpprovider.defaults.headers.post['x-csrftoken'] = $cookies.csrftoken; }]);
and controllers.js
function homectrl($scope, $http){ $http.get('/api/games-pending-entry').success(function(data){ $scope.games_pending_entry = data; }); } function shortlistctrl($scope, $http, $routeparams){ $scope.gameid = $routeparams.gameid; $http.get('api/get-players').success(function(data){ $scope.players = data; }) }
and in html, calling link as
<a class='btn btn-warning' href='#/game/{{ game.id }}'>enter shortlist</a>
when click on link, redirected /#/
where going wrong?
your $routeprovider rules wrong:
when('game/:gameid',{
should become
when('/game/:gameid',{
as route isn't recognized, redirects '/'. changing solve problem.
also, may find nghref useful, avoid having links broken, before {{model}} bindings resolved: http://docs.angularjs.org/api/ng.directive:nghref
Comments
Post a Comment