Guest User

Untitled

a guest
Aug 4th, 2018
435
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. import { Component, OnInit, Input } from '@angular/core';
  2. import { NgForm } from '@angular/forms';
  3.  
  4. import { Employee } from '../employee.model';
  5. import { EmployeeService } from '../employee.service';
  6. import { Router } from '../../../../node_modules/@angular/router';
  7.  
  8.  
  9.  
  10.  
  11. @Component({
  12. selector: 'app-create-employee',
  13. templateUrl: './create-employee.component.html',
  14. styleUrls: ['./create-employee.component.css']
  15. })
  16. export class CreateEmployeeComponent implements OnInit {
  17.  
  18. @Input() employee: Employee;
  19.  
  20.  
  21. photoPreview = false;
  22.  
  23. constructor(private empService: EmployeeService,
  24. private router: Router
  25. ) { }
  26.  
  27. ngOnInit() {
  28.  
  29. }
  30.  
  31. onSaveEmp(empForm: NgForm) {
  32. //console.log(empForm.value);
  33. }
  34.  
  35. saveEmployee(employee: Employee) {
  36. this.empService.save(employee);
  37. 'The Array of Form' + console.log(employee);
  38. }
  39.  
  40. onShowPreview() {
  41. this.photoPreview = !this.photoPreview;
  42. }
  43. }
  44.  
  45. import { Injectable, OnInit } from "@angular/core";
  46.  
  47. import { Employee } from "./employee.model";
  48.  
  49. @Injectable({
  50. providedIn: 'root',
  51. })
  52.  
  53. export class EmployeeService implements OnInit {
  54.  
  55. private employees: Employee[] = [
  56. new Employee('John', 'Male', 'john@gmail.com', 1234567890, 'Phone', new Date('06/10/1991'),'IT', true, 'assets/images/male.png'),
  57. new Employee('sunria', 'Female', 'sunria@gmail.com', 9876543211, 'Phone', new Date('06/30/1991'),'HR', true, 'assets/images/female.png'),
  58. new Employee('Sandy', 'Female', 'sandy@gmail.com', 12344509876, 'Phone', new Date('02/28/2002'),'Manager', true, 'assets/images/female2.png')
  59. ]
  60.  
  61. constructor() {
  62.  
  63. }
  64.  
  65. ngOnInit() {}
  66.  
  67. getEmployees() {
  68. return this.employees.slice();
  69. }
  70.  
  71. save(employee: Employee) {
  72. this.employees.push(employee);
  73. }
Add Comment
Please, Sign In to add comment