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')
DetailPage.jade
, but you didn't list the contents of that page in the question....$http.get
request for an HTML page instead of usinga href=
?