File

src/app/specialties/specialty-list/specialty-list.component.ts

Implements

OnInit

Metadata

selector app-specialty-list
styleUrls ./specialty-list.component.css
templateUrl ./specialty-list.component.html

Index

Properties
Methods

Constructor

constructor(specService: SpecialtyService, router: Router)
Parameters :
Name Type Optional
specService SpecialtyService No
router Router No

Methods

deleteSpecialty
deleteSpecialty(specialty: Specialty)
Parameters :
Name Type Optional
specialty Specialty No
Returns : void
gotoHome
gotoHome()
Returns : void
ngOnInit
ngOnInit()
Returns : void
onNewSpecialty
onNewSpecialty(newSpecialty: Specialty)
Parameters :
Name Type Optional
newSpecialty Specialty No
Returns : void
showAddSpecialtyComponent
showAddSpecialtyComponent()
Returns : void
showEditSpecialtyComponent
showEditSpecialtyComponent(updatedSpecialty: Specialty)
Parameters :
Name Type Optional
updatedSpecialty Specialty No
Returns : void

Properties

errorMessage
Type : string
isInsert
Default value : false
responseStatus
Type : number
specialties
Type : Specialty[]
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>

./specialty-list.component.css

/*
 *
 *  * 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
Component
Html element with directive

result-matching ""

    No results matching ""