This file contains hidden or 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 User = require('../model/user'); | |
var mongoose = require('mongoose'); | |
var router = express.Router(); | |
router.post('/insertUser', function(req, res, next) { | |
var newUser = new User(req.body); | |
newUser._id = mongoose.Types.ObjectId(); |
This file contains hidden or 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
<div class="col-sm-8"> | |
<div class="row"> | |
<div class="col-sm-2"> | |
<label for="Name">Name</label> | |
</div> | |
<div class="col-sm-2"> | |
<label for="Blog">Blog</label> | |
</div> | |
<div class="col-sm-2"> | |
<label for="Age">Age</label> |
This file contains hidden or 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
import { Component, OnInit, ViewEncapsulation } from '@angular/core'; | |
import { User } from '../model/user'; | |
import { UserService} from '../services/users.service'; | |
@Component({ | |
selector: 'users', | |
templateUrl: './users.component.html', | |
}) | |
export class UserComponent implements OnInit { |
This file contains hidden or 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
@Injectable() | |
export class UserService { | |
constructor(private http: Http) { | |
} | |
getUsers(searchCriteria:any) : Observable<User[]>{ | |
let params: URLSearchParams = new URLSearchParams(); | |
params.set('name', searchCriteria); |
This file contains hidden or 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 router = express.Router(); | |
router.get('/getUsers', function(req, res, next) { | |
var searchQuery = {}; | |
if(req.query.name) | |
searchQuery = { name: req.query.name }; | |
User.find(searchQuery, function(err, users){ | |
if (err) { |
This file contains hidden or 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
<div class="form-group col-sm-2"> | |
<label for="editUser">Edit User:</label> | |
<input class="form-control" type="text" placeholder="Name" [(ngModel)]="this.editUser.name" [ngModelOptions]="{standalone: true}"/> | |
<input class="form-control" type="text" placeholder="Blog" [(ngModel)]="this.editUser.blog" [ngModelOptions]="{standalone: true}"/> | |
<input class="form-control" type="text" placeholder="Age" [(ngModel)]="this.editUser.age" [ngModelOptions]="{standalone: true}"/> | |
<input class="form-control" type="text" placeholder="Location" [(ngModel)]="this.editUser.location" [ngModelOptions]="{standalone: true}"/> | |
<button class="btn btn-default" (click)="updateUser()"> Edit User </button> | |
</div> |
This file contains hidden or 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
import { Component, OnInit, ViewEncapsulation } from '@angular/core'; | |
import { User } from '../model/user'; | |
import { UserService} from '../services/users.service'; | |
@Component({ | |
selector: 'users', | |
templateUrl: './users.component.html', | |
}) | |
export class UserComponent implements OnInit { |
This file contains hidden or 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
@Injectable() | |
export class UserService { | |
constructor(private http: Http) { | |
} | |
updateUser(user:User): Observable<any>{ | |
return this.http.post("http://localhost:3000/updateUser", user) | |
.map((res:any) => { | |
return res.json(); |
This file contains hidden or 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
router.post('/updateUser', function(req, res, next) { | |
var user = new User(req.body); | |
User.update({_id : user.id}, user, function(err) { | |
if (err) { | |
console.log("not updated!"); | |
res.status(400); | |
res.send(); | |
} |
This file contains hidden or 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
deleteUser(user:User) | |
{ | |
this.userService.deleteUser(user) | |
.subscribe( | |
data => { | |
this.users.splice(this.users.indexOf(user), 1); | |
console.log("User deleted!"); | |
}) | |
} |