0

I have an <ng-view></ng-view> that is filled with a partial html file when a button is clicked i.e <a href="/#/signin">Sign In</a>

myApp.js

var myApp = angular.module("myApp", ['ngRoute']);

//Define Routing for app
myApp.config(['$routeProvider',
  function($routeProvider) {
    $routeProvider.
      when('/signin', {
        templateUrl: 'signin.ejs'
      }).
      when('/signup', {
        templateUrl: 'signup.ejs'
      }).
      when('/myAccount', {
        templateUrl: 'myAccount.ejs'
      }).
      otherwise({
        //home page
      });
}]);

What I want to know is, how can fill this ng-view based on data that is sent by the server. For example, if the server renders the index.html with data {page: '/signin'} how can I let Angular know that I want to to populate the ng-view with 'signin.ejs'??

Any help is appreciated. Thank you!!

EDIT: I have someone logged in to the site and on a page I provide a "switch account" button. So what I want to do is, when that is clicked, post to the server /logout route so the session can be cleared, and then change the page to the signin page (partial html file) and populate the username field with the account that they are switching to

Elementary
  • 399
  • 2
  • 5
  • 17

1 Answers1

0

Your ejs needs to be rendered by nodejs so you need to apply your the routing there.

You need to come up with a way to identify the route path like '/partials/:filename'

app.route('/partials/:filename').get(funcs.partials);

Then you handle the request and render your ejs or plain you just send(html) and you use the path module to locate and manipulate the url string.

exports.partials = function(req, res, next, filename) {
    res.render(filename, vars);
};

Then your angular is like, though signin is probably not the best example.

  $routeProvider.
    when('/signin', {
      templateUrl: '/partials/signin'
    })
Dylan
  • 4,703
  • 1
  • 20
  • 23
  • Thank you for your answer! I think this is bit different from what I'm trying to do though. I have someone logged in to the site and on a page I provide a "switch account" button. So what I want to do is, when that is clicked, post to the server /logout route so the session can be cleared, and then change the page to the signin page (partial html file) and populate the username field with the account that they are switching to – Elementary Jul 19 '14 at 14:18
  • I don't use partials with ejs myself because in a single page app I would prefer to send all content as a '$resource' as json. So angular templates are only plain html with angular bindings. I would really only use this for the index but I still serve/send the templates with node. – Dylan Jul 19 '14 at 19:09