Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.84 KB | None | 0 0
  1. <h2>Add Employee:</h2>
  2. <form class="form-horizontal" #empForm="ngForm">
  3. <div class="form-group">
  4. <label class="control-label col-sm-2" for="name">Name:</label>
  5. <div class="col-sm-10">
  6. <input type="text" class="form-control" name="name" minlength="4" maxlength="10" pattern="^[A-Za-z0-9]*[A-Za-z0-9][A-Za-z0-9]S*$" [(ngModel)]="model.name" placeholder="Enter Your Name"
  7. #name="ngModel" required/>
  8. <div *ngIf="name.invalid && (name.dirty || name.touched)" class="alert alert-danger">
  9. <div *ngIf="name.errors.required">
  10. Name is required.
  11. </div>
  12. <div *ngIf="name.errors.pattern">
  13. No Spaces
  14. </div>
  15. <div *ngIf="name.errors.minlength">
  16. Name must be at least 4 characters long.
  17. </div>
  18. </div>
  19. </div>
  20. </div>
  21. <div class="form-group">
  22. <label class="control-label col-sm-2" for="position">Position:</label>
  23.  
  24. <div class="col-sm-10">
  25. <input type="text" class="form-control" name="position" minlength="4" maxlength="10" pattern="^[a-z]*$" [(ngModel)]="model.position" placeholder="Enter your position"
  26. #position="ngModel" required />
  27. <div *ngIf="position.invalid && (position.dirty || position.touched)" class="alert alert-danger">
  28. <div *ngIf="position.errors.required">
  29. Position is required.
  30. </div>
  31. <div *ngIf="position.errors.pattern">
  32. Only Alphabets are must be entered
  33. </div>
  34. <div *ngIf="position.errors.minlength">
  35. Position must be at least 4 characters long.
  36. </div>
  37. </div>
  38. </div>
  39. </div>
  40. <div class="form-group">
  41. <label class="control-label col-sm-2" for="salary">Salary:</label>
  42. <div class="col-sm-10">
  43. <input type="text" class="form-control" name="salary" pattern="[0-9]*"
  44. minlength="5" maxlength="7" [(ngModel)]="model.salary" placeholder="Enter Salary" #salary="ngModel" required />
  45. <div *ngIf="salary.invalid && (salary.dirty || salary.touched)" class="alert alert-danger">
  46. <div *ngIf="salary.errors.required">
  47. Salary is required.
  48. </div>
  49. <div *ngIf="salary.errors.minlength">
  50. Salary must be in 5 numbers.
  51. </div>
  52. <div *ngIf="salary.errors.maxlength">
  53. Salary must not be exceeded morethan 7 numbers.
  54. </div>
  55.  
  56. <div *ngIf="salary.errors?.pattern">Only numebers should be typed
  57. </div>
  58. </div>
  59. </div>
  60. </div>
  61. <div class="form-group">
  62. <div class="col-sm-offset-2 col-sm-10">
  63. <button type="submit" class="btn btn-default" routerLink="../viewemployee" [disabled]="empForm.invalid">Add Employee</button>
  64. <button type="button" class="btn btn-default" routerLink="../home">Cancel</button>
  65. </div>
  66. </div>
  67. </form>
  68.  
  69. import { Component, OnInit } from '@angular/core';
  70. import { FormControl, FormGroup , Validators} from '@angular/forms';
  71. import { FormsModule, ReactiveFormsModule } from '@angular/forms';
  72.  
  73. @Component({
  74. selector: 'app-createemployee',
  75. templateUrl: './createemployee.component.html',
  76. styleUrls: ['./createemployee.component.css']
  77. })
  78.  
  79. export class CreateemployeeComponent implements OnInit {
  80.  
  81. model: any = {};
  82. model2: any = {};
  83. add=false;
  84. create=true;
  85.  
  86. ngOnInit() {
  87. this.model = new FormGroup({
  88. 'name': new FormControl(this.model.name,
  89. [Validators.required, Validators.minLength(4),]),
  90. 'position': new FormControl(this.model.position,
  91. [Validators.required, Validators.minLength(4),]),
  92. 'salary': new FormControl(this.model.salary, Validators.required)
  93. });
  94. }
  95.  
  96. employees = [{name: "Sunil", position: "Developer", salary: 20000},
  97. {name: "Vamshi", position: "Java Developer", salary: 30000},
  98. {name: "Chethan", position: ".Net Developer", salary: 10000}];
  99.  
  100. createEmp(){
  101. this.add=true;
  102. this.create=false;
  103. this.Show=false;
  104. this.edit=false;
  105. }
  106. addEmployee() {
  107. this.employees.push(this.model);
  108. this.Show = true;
  109. this.add = false;
  110. this.model = {};
  111. }
  112. }
  113.  
  114. <h2>Employee Details</h2>
  115. <table class="table table-bordered">
  116. <thead>
  117. <tr>
  118. <th width=400>Name</th>
  119. <th width=400>Position</th>
  120. <th width=200>Salary</th>
  121. <th width=400>Actions</th>
  122. </tr>
  123. </thead>
  124. <tbody>
  125. <tr *ngFor="let employee of employees; let i=index">
  126. <td>{{employee.name}}</td>
  127. <td>{{employee.position}}</td>
  128. <td>{{employee.salary}}</td>
  129. <td>
  130. <a class="btn btn-success" (click)="editEmployee(i)">Edit</a>
  131. <a class="btn btn-danger" (click)="deleteEmployee(i)">Delete</a>
  132. </td>
  133. </tr>
  134. </tbody>
  135. </table>
  136.  
  137. import { ModuleWithProviders } from '@angular/core';
  138. import { Routes, RouterModule } from '@angular/router';
  139.  
  140. import { AppComponent } from './app.component';
  141. import { HomeComponent } from './home/home.component';
  142. import { CreateemployeeComponent } from './createemployee/createemployee.component';
  143. import { ViewemployeeComponent } from './viewemployee/viewemployee.component';
  144. import { UpdateemployeeComponent } from './updateemployee/updateemployee.component';
  145.  
  146. export const router: Routes = [
  147. { path: '',redirectTo: 'home',pathMatch: 'full'},
  148. { path: 'createemployee', component: CreateemployeeComponent },
  149. { path: 'updateemployee', component: UpdateemployeeComponent},
  150. { path: 'viewemployee', component: ViewemployeeComponent },
  151. { path: 'home', component: HomeComponent},
  152. { path: 'appcomponent', component: AppComponent}
  153. ];
  154.  
  155. export const routes: ModuleWithProviders = RouterModule.forRoot(router)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement