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 { ApiService } from './service/api.service'; | |
@NgModule({ | |
providers: [ApiService] | |
}) |
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 { Injectable } from '@angular/core'; | |
import { Observable, throwError } from 'rxjs'; | |
import { catchError, map } from 'rxjs/operators'; | |
import { HttpClient, HttpHeaders, HttpErrorResponse } from '@angular/common/http'; | |
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class ApiService { | |
baseUri:string = 'http://localhost:3000'; | |
headers = new HttpHeaders().set('Content-Type', 'application/json');constructor(private http: HttpClient) { } |
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
export class Employee { | |
name: string; | |
email: string; | |
designation: string; | |
phoneNumber: number; | |
constructor(name: string, email: string, designation: string, phoneNumber: number){ | |
this.name = name; | |
this.email = email; | |
this.designation = designation; |
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 { HttpClientModule } from '@angular/common/http'; | |
@NgModule({ | |
imports: [ | |
HttpClientModule | |
] | |
}) |
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
<nav> | |
<a routerLinkActive="active" routerLink="/employees-list">View Employees</a> | |
<a routerLinkActive="active" routerLink="/create-employee">Add Employee</a> | |
</nav><router-outlet></router-outlet> |
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 { NgModule } from '@angular/core'; | |
import { Routes, RouterModule } from '@angular/router'; | |
import { BrowserModule } from '@angular/platform-browser'; | |
import { FormsModule, ReactiveFormsModule } from '@angular/forms'; | |
import { AppRoutingModule } from './app-routing.module'; | |
import { AppComponent } from './app.component'; | |
import { EmployeeCreateComponent } from './components/employee-create/employee-create.component'; | |
import { EmployeeEditComponent } from './components/employee-edit/employee-edit.component'; | |
import { EmployeeListComponent } from './components/employee-list/employee-list.component';import { HttpClientModule } from '@angular/common/http'; | |
import { ApiService } from './service/api.service';const routes: Routes = [ |
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'), | |
app = express(), | |
port = process.env.PORT || 3000, | |
mongoose = require('mongoose'), | |
cors = require('cors'), | |
bodyParser = require('body-parser'), | |
Employee = require('./models/employee'); | |
mongoose.Promise = global.Promise; | |
mongoose.connect('mongodb://localhost:27017/empdb', { useNewUrlParser: true, useUnifiedTopology: true }) | |
.then(() => { |
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
module.exports = function(app) { | |
var employee = require('./../controllers/employee'); | |
app.route('/') | |
.get(employee.listAllEmployee) | |
app.route('/employee') | |
.get(employee.listAllEmployee) | |
.post(employee.createEmployee); | |
app.route('/employee/:employeeId') | |
.get(employee.readEmployee) | |
.put(employee.updateEmployee) |
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 mongoose = require('mongoose'), | |
Employee = mongoose.model('Employee'); | |
exports.listAllEmployee = function(req, res) { | |
Employee.find({}, function(err, Employee) { | |
if (err) | |
res.send(err); | |
res.json(Employee); | |
}); | |
}; | |
exports.createEmployee = function(req, res) { |
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
const mongoose = require('mongoose'); | |
const Schema = mongoose.Schema; | |
// Define collection and schema | |
let Employee = new Schema({ | |
name: { | |
type: String | |
}, | |
email: { | |
type: String | |
}, |