Guest User

Untitled

a guest
Apr 19th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.36 KB | None | 0 0
  1. import { Router } from '@angular/router';
  2. import { IExCon } from "../../examconfig";
  3.  
  4. @Component({
  5. selector: 'app-edit-exam',
  6. templateUrl: './edit-exam.component.html',
  7. styleUrls: ['./edit-exam.component.css']
  8. })
  9. export class EditExamComponent implements OnInit {
  10.  
  11.  
  12. examid:string;
  13. myexam: IExCon[];
  14. exam: string;
  15. topic: string;
  16. description: string;
  17. noof:string;
  18. timer: string;
  19. creat: boolean = true;
  20. message:string;
  21.  
  22.  
  23. constructor(private apiService: ExamService,private router: Router) { }
  24.  
  25.  
  26. ngOnInit() {
  27.  
  28. this.apiService.castexamid.subscribe(data =>
  29. {
  30. this.examid = data;
  31. });
  32.  
  33. this.apiService.getaExam(this.examid)
  34. .subscribe(
  35. resultArray => {
  36. this.myexam = resultArray;
  37. this.exam = JSON.stringify(this.myexam);
  38.  
  39. this.topic = this.myexam[0].topic;
  40. this.description = this.myexam[0].description;
  41. this.noof = this.myexam[0].noofq;
  42. this.timer = this.myexam[0].timer;
  43.  
  44.  
  45. })
  46. }
  47.  
  48.  
  49. save(){
  50.  
  51. this.apiService.EditExam(this.examid,this.topic,this.description,this.noof,this.timer);
  52. this.creat = false;
  53. this.message = '';
  54.  
  55. }
  56.  
  57. gohome(){
  58. this.router.navigate(['']);
  59. }
  60.  
  61. goback(){
  62. this.router.navigate(['showexams']);
  63. }
  64.  
  65. OnTopic(event:any)
  66. {
  67. this.topic = event.target.value;
  68. }
  69.  
  70. onDesc(event:any)
  71. {
  72. this.description = event.target.value;
  73. }
  74.  
  75. onNoof(event:any)
  76. {
  77. this.noof = event.target.value;
  78. }
  79.  
  80. onTimer(event:any)
  81. {
  82. this.timer = event.target.value;
  83. }
  84. }
  85.  
  86. <form>
  87. <div *ngFor="let item of myexam">
  88. <div *ngIf="creat;else created">
  89. <div class="container">
  90. <div class="row">
  91. <div class="span12">
  92. <!-- <form> -->
  93. <fieldset>
  94. <div class="control-group">
  95.  
  96. <div class="controls">
  97. <label for="topic">Topic</label>
  98. <input type="text" id="topic" name="topic" [ngModel]="item.Topic" class="input-xlarge" (keyup)="OnTopic($event)">
  99. </div>
  100. </div>
  101. <br>
  102. <div class="control-group">
  103.  
  104. <div class="controls">
  105. <label for="description">Description</label>
  106. <input type="text" id="description" name="description" [ngModel]="item.Description" class="input-xlarge" (keyup)="onDesc($event)">
  107. </div>
  108. </div>
  109. <br>
  110. <div class="control-group">
  111.  
  112. <div class="controls">
  113. <label for="noof">No of Questions</label>
  114. <input type="text" id="noof" name="noof" [ngModel]="item.Noofq" class="input-xlarge" (keyup)="onNoof($event)">
  115. </div>
  116. </div>
  117. <br>
  118. <div class="control-group">
  119.  
  120. <div class="controls">
  121. <label for="timer">Timer</label>
  122. <input type="text" id="timer" name="timer" [ngModel]="item.Timer" class="input-xlarge" (keyup)="onTimer($event)">
  123. </div>
  124. </div>
  125. <div class="control-group">
  126. <br>
  127. <div class="controls">
  128. <button type="button" class="btn btn-primary" (click)="save()">Save</button>
  129. </div>
  130. <br>
  131. <div class="controls">
  132. <button type="button" class="btn btn-primary" (click)="goback()">Cancel</button>
  133. </div>
  134. </div>
  135. </fieldset>
  136.  
  137.  
  138. </div>
  139. </div>
  140. </div>
  141. </div>
  142. <ng-template #created>
  143. <h2>Exam Edited Successfully</h2><br>
  144. <button type="button" (click)="gohome()">Go to Home page</button>
  145. </ng-template>
  146. </div>
  147. </form>
Add Comment
Please, Sign In to add comment