Wednesday, 19 April 2017

Angular Controller returns 404 on a Route Parameter

I'm building my first web app with Node.js and AngularJs. My problem lies in this code here:

var app = angular.module('Martin', ['ngResource','ngRoute']);

app.config(['$routeProvider', function($routeProvider){
    $routeProvider
        .when('/', {
            templateUrl: 'partials/home.html',
            controller: 'PageCtrl'
        })
        .when('/etx/:id', {
            templateUrl: 'partials/page.html',
            controller: 'PageCtrl'
        });
}]);

app.controller('PageCtrl', ['$scope', '$resource', '$routeParams',
    function($scope, $resource, $routeParams){
        console.log('Got here');
        var Page = $resource('/api/pages/:id');
        Page.get({ id: $routeParams.id }, function(page){
            $scope.page = page;
        });
    }]);

From what I understand, if I were to request /etx/mypage, the function in PageCtrl should be run, but when I try to pull it up in a browser, I get a 404 error and nothing is printed to the console.

I tested it with the home page ('/'), and the controller works fine then.



via jpyams

No comments:

Post a Comment