File

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

Implements

OnInit

Metadata

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

Index

Properties
Methods

Constructor

constructor(specialtyService: SpecialtyService, route: ActivatedRoute, router: Router)
Parameters :
Name Type Optional
specialtyService SpecialtyService No
route ActivatedRoute No
router Router No

Methods

ngOnInit
ngOnInit()
Returns : void
onBack
onBack()
Returns : void
onSubmit
onSubmit(specialty: Specialty)
Parameters :
Name Type Optional
specialty Specialty No
Returns : void

Properties

errorMessage
Type : string
specialty
Type : Specialty
import {Component, OnInit} from '@angular/core';
import {Specialty} from '../specialty';
import {SpecialtyService} from '../specialty.service';
import {ActivatedRoute, Router} from '@angular/router';

@Component({
  selector: 'app-specialty-edit',
  templateUrl: './specialty-edit.component.html',
  styleUrls: ['./specialty-edit.component.css']
})
export class SpecialtyEditComponent implements OnInit {
  specialty: Specialty;
  errorMessage: string;

  constructor(private specialtyService: SpecialtyService, private route: ActivatedRoute, private router: Router) {
    this.specialty = {} as Specialty;
  }

  ngOnInit() {
    const specId = this.route.snapshot.params.id;
    this.specialtyService.getSpecialtyById(specId).subscribe(
      specialty => this.specialty = specialty,
      error => this.errorMessage = error as any);
  }

  onSubmit(specialty: Specialty) {
    this.specialtyService.updateSpecialty(specialty.id.toString(), specialty).subscribe(
      res => {
        console.log('update success');
        this.onBack();
      },
      error => this.errorMessage = error as any);
 }

  onBack() {
    this.router.navigate(['/specialties']);
  }

}
<!--
  ~ /*
  ~  * Copyright 2017-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>Edit Specialty</h2>
    <form id="specialty" class="form-horizontal" (ngSubmit)="onSubmit(specialtyForm.value)" #specialtyForm="ngForm">
      <div class="form-group" hidden="true">
        <input type="text" hidden="true" class="form-control" id="id" [(ngModel)]="specialty.id" name="id"/>
      </div>
      <div class="form-group has-feedback">
        <div class="form-group ">
          <label class="col-sm-1 control-label">Name</label>
          <div class="col-sm-6">
            <input id="name" name="name" class="form-control" type="text" [(ngModel)]="specialty.name"/>
          </div>
          <button class="btn btn-default" type="submit">Update</button>
          <button class="btn btn-default" (click)="onBack()">Cancel</button>
        </div>
      </div>
    </form>
  </div>
</div>

./specialty-edit.component.css

Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""