Express and AngularJS - web page freezes when attempting to open home page Express and AngularJS - web page freezes when attempting to open home page express express

Express and AngularJS - web page freezes when attempting to open home page


Finally figured it out - after many intense moments of hair pulling!!
The reason why the page freezes is because (explained step by step):

  1. User launches localhost:3000
  2. This requests the express server for '/'
  3. Express renders index.html
  4. AngularJS will render the template 'partials/test.html'.
  5. Here, I am taking a wild guess - AngularJS has made a HTTP request for the page 'partials/test.html'.
  6. However, you can see that express or rather app.js does not have a handler for this GET request. That is, the following code is missing:

    app.get('partials/:name', function(request, response) {
    var name = request.params.name;
    response.render('partials/' + name);
    });

inside app.js of the ROOT directory. Once I add this code, the page renders as expected.


Try following the design pattern in this working fiddle. Code shown below. You can replace the template option with templateUrl and it should still work fine.

var app = angular.module('app', []);app.config(['$routeProvider', function($routeProvider){    $routeProvider.when('/', {template: '<p>Index page</p>', controller: 'IndexCtrl'});    $routeProvider.otherwise({redirect:'/'});}]);app.controller('IndexCtrl', function(){});