File
Implements
Metadata
| selector |
app-specialty-list |
| styleUrls |
./specialty-list.component.css |
| templateUrl |
./specialty-list.component.html |
Methods
|
deleteSpecialty
|
deleteSpecialty(specialty: Specialty)
|
|
|
|
|
|
onNewSpecialty
|
onNewSpecialty(newSpecialty: Specialty)
|
|
|
|
|
|
showAddSpecialtyComponent
|
showAddSpecialtyComponent()
|
|
|
|
|
|
showEditSpecialtyComponent
|
showEditSpecialtyComponent(updatedSpecialty: Specialty)
|
|
|
Parameters :
| Name |
Type |
Optional |
| updatedSpecialty |
Specialty
|
No
|
|
|
isInsert
|
Default value : false
|
|
|
import {Component, OnInit} from '@angular/core';
import {Specialty} from '../specialty';
import {SpecialtyService} from '../specialty.service';
import {Router} from '@angular/router';
@Component({
selector: 'app-specialty-list',
templateUrl: './specialty-list.component.html',
styleUrls: ['./specialty-list.component.css']
})
export class SpecialtyListComponent implements OnInit {
specialties: Specialty[];
errorMessage: string;
responseStatus: number;
isInsert = false;
constructor(private specService: SpecialtyService, private router: Router) {
this.specialties = [];
}
ngOnInit() {
this.specService.getSpecialties().subscribe(
specialties => this.specialties = specialties,
error => this.errorMessage = error as any);
}
deleteSpecialty(specialty: Specialty) {
this.specService.deleteSpecialty(specialty.id.toString()).subscribe(
response => {
this.responseStatus = response;
this.specialties = this.specialties.filter(currentItem => !(currentItem.id === specialty.id));
},
error => this.errorMessage = error as any);
}
onNewSpecialty(newSpecialty: Specialty) {
this.specialties.push(newSpecialty);
this.showAddSpecialtyComponent();
}
showAddSpecialtyComponent() {
this.isInsert = !this.isInsert;
}
showEditSpecialtyComponent(updatedSpecialty: Specialty) {
this.router.navigate(['/specialties', updatedSpecialty.id.toString(), 'edit']);
}
gotoHome() {
this.router.navigate(['/welcome']);
}
}
<!--
~ /*
~ * Copyright 2016-2018 the original author or authors.
~ *
~ * Licensed under the Apache License, Version 2.0 (the "License");
~ * you may not use this file except in compliance with the License.
~ * You may obtain a copy of the License at
~ *
~ * http://www.apache.org/licenses/LICENSE-2.0
~ *
~ * Unless required by applicable law or agreed to in writing, software
~ * distributed under the License is distributed on an "AS IS" BASIS,
~ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ * See the License for the specific language governing permissions and
~ * limitations under the License.
~ */
-->
<div class="container-fluid">
<div class="container xd-container">
<h2>Specialties</h2>
<table id="specialties" class="table table-striped">
<thead>
<tr>
<th>Name</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr *ngFor="let specialty of specialties; let element_id=index">
<td>
<input [id]=element_id [readonly]="true" type="text" class="form-control" [(ngModel)]="specialty.name" name="spec_name" />
</td>
<td>
<button class="btn btn-default" (click)="showEditSpecialtyComponent(specialty)">Edit</button>
<button class="btn btn-default" (click)="deleteSpecialty(specialty)">Delete</button>
</td>
</tr>
</tbody>
</table>
<div *ngIf="isInsert">
<app-specialty-add (newSpeciality)="onNewSpecialty($event)">...</app-specialty-add>
</div>
<div>
<button class="btn btn-default" (click)="gotoHome()">Home</button>
<button class="btn btn-default" (click)="showAddSpecialtyComponent()"> Add </button>
</div>
</div>
</div>
/*
*
* * Copyright 2016-2017 the original author or authors.
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
*
*/
Legend
Html element with directive