import { Component , OnInit , ViewChild } from '@angular/core' ; import { NgForm } from '@angular/forms' ; import { ActivatedRoute , Router } from '@angular/router' ; import { NzNotificationService } from 'ng-zorro-antd' ; import { ArticleTypeModel } from '../model/articletype.model' ; import { EditArticleTypeService } from './editarticletype.service' ; @ Component ( { selector : 'app-edit-articletype' , templateUrl : './editarticletype.html' , } ) export class EditArticleTypeComponent implements OnInit { public isConfirmLoading = false ; public editArticleType : ArticleTypeModel = new ArticleTypeModel ( ) ; @ ViewChild ( 'form' , { static : false } ) private form : NgForm ; constructor ( private router , private route , private editArticleTypeService , private notification ) { } public ngOnInit ( ) { this . route . params . subscribe ( ( param ) => { if ( param . id ) { this . getData ( param . id ) ; } } , ( err ) => { this . notification . warning ( '错误' , '参数错误' ) ; } ) ; } public getData ( id ) { this . editArticleTypeService . getArticleType ( id ) . subscribe ( ( res ) => { this . editArticleType = res . data ; } , ( err ) => { } ) ; } public save ( ) { for ( const i in this . form . controls ) { this . form . controls [ i ] . markAsDirty ( ) ; } if ( this . form . valid ) { this . isConfirmLoading = true ; this . editArticleTypeService . updateArticleType ( this . editArticleType ) . subscribe ( ( res ) => { this . isConfirmLoading = false ; this . notification . success ( '成功' , res . msg ) ; this . router . navigate ( [ '/articletype' ] ) ; } , ( err ) => { this . isConfirmLoading = false ; } ) ; } } public back ( ) { this . router . navigate ( [ './articletype' ] ) ; } }