0

I am using NodeJS-Express-Jade-AngularJS, when i type in http:localhost:3000 i get my page which has table with a select button on each row. When the user clicks on corresponding row's select button i call a http get and pass in the selected row's ID as url string. My server returns me a new page but i don't know how to load that new page back in the browser

server.js code

app.get('/', function(req, res) {
  console.log('Home Page GET Request');  
  res.render('HomePage', { title: 'Demo App'});  
});
app.get('/id=:id', function (req, res) {  
  res.render('DetailPage', { title: 'Demo App'}); 
});

controller.js

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

myApp.controller('AppCtrl', ['$scope', '$http', '$location', function($scope, $http, $location) {
    var refresh = function() {
        $http.get('/HomePage').success(function(response) {
            $scope.list = response;
        });
    };

    refresh();

    $scope.select = function(id) {
        console.log(id);     
        $http.get('/id=' + id).success(function(response) {    
            // My response contains html code but how to display it in browser
        });      
    };
}]);

HomePage.jade

body
    .container(ng-controller='AppCtrl')
      h1 My List
      table.table
        thead
          tr
            th ID
            th Name
            th Action
            th  
        tbody
          tr(ng-repeat='contact in contactlist')
            td {{contact.Id}}
            td {{contact.Name}}
            td
              button.btn.btn-info(ng-click='select(contact.Id)') Select

DetailPage.jade

html(ng-app='myApp')


head
    // Latest compiled and minified CSS
    link(rel='stylesheet', href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css')
    // Optional theme
    link(rel='stylesheet', href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap-theme.min.css')
    title!= title
  body    
    .panel.panel-default
      .panel-heading
        h3.panel-title!= Paneltitle
      .panel-body
        | Panel content
    script(src='http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.3/angular.js')  
    script(src='http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.3/angular-route.min.js')     
    script(src='/controllers/controller.js')
3
  • what do you mean you don't know how to load the new page into the browser? I'm assuming that you mean your server renders DetailPage.jade, but you didn't list the contents of that page in the question.... Commented Aug 10, 2015 at 20:47
  • 1
    for that matter, why would you make an $http.get request for an HTML page instead of using a href=? Commented Aug 10, 2015 at 20:49
  • 1
    Thanks that worked with a href, also i was wrongly calling $location.path('/id=' + id); after calling $http.get. I removed the get request and called $location.path('/id=' + id); in the select method Commented Aug 10, 2015 at 22:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.