This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var app = express(); | |
app.listen(3000); | |
console.log("server running on port 3000"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var app = express(); | |
app.use(express.static(__dirname)); | |
app.get('/persons', function(req, res){ | |
console.log('Received find all persons request'); | |
}); | |
app.get('/person/:id', function(req, res){ | |
console.log('Received findOne person request'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
var app = angular.module("addressBookApp", ['ngRoute', 'angular-loading-bar']); | |
app.config(function ($routeProvider) { | |
$routeProvider | |
.when("/person", { | |
templateUrl: 'app/views/person.html', | |
controller: "PersonCtrl" | |
}) | |
.when("/person/:personId", { | |
templateUrl: 'app/views/persondetail.html', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//delete person | |
$scope.deletePerson = function(id){ | |
$http.delete('/deletePerson/' + id) | |
.then(onPersonDeleteCompleted, onError); | |
console.log(id); | |
}; | |
var onPersonDeleteCompleted = function(response){ | |
$scope.person = response.data; | |
console.log(response.data); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//common error function | |
var onError = function (error) { | |
$scope.error = error.data; | |
}; | |
//end error function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//get persons by Id | |
var onGetByIdCompleted = function(response){ | |
$scope.person = response.data; | |
console.log(response.data); | |
}; | |
$scope.searchPerson = function(id){ | |
$http.get('/person/' + id) | |
.then(onGetByIdCompleted, onError); | |
console.log(id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//get all persone | |
var onPersonGetCompleted = function(response){ | |
$scope.persons = response.data; | |
console.log($scope.persons); | |
} | |
var refresh = function(){ | |
$http.get('/persons') | |
.then(onPersonGetCompleted, onError); | |
console.log('Response received...'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//update person | |
$scope.updatePerson = function(person){ | |
$http.put("/updatePerson", person) | |
.then(onUpdatePersonCompleted, onError); | |
console.log(person); | |
}; | |
var onUpdatePersonCompleted = function(response){ | |
$scope.person = null;//response.data; | |
console.log(response.data); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//add new person | |
var onAddPersonCompleted = function(response){ | |
$scope.person = response.data; | |
console.log(response.data); | |
refresh(); | |
}; | |
$scope.addPerson = function(person){ | |
$http.post('/addPerson', person) | |
.then(onAddPersonCompleted, onError); | |
console.log(person); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
(function () { | |
var addressBookApp = angular.module("addressBookApp"); | |
var PersonCtrl = function ($scope, $http) | |
{ | |
$scope.working = 'Angular is Working'; | |
//common error function | |
var onError = function (error) { |
OlderNewer