import { Component , OnInit } from '@angular/core' ; import { UserService } from '../../../../service/user.service' ; import { NzMessageService } from 'ng-zorro-antd' ; import { Router , ActivatedRoute } from '@angular/router' ; @ Component ( { selector : 'nz-user-edit' , templateUrl : './user-edit.component.html' , styleUrls : [ './user-edit.component.less' ] } ) export class UserEditComponent implements OnInit { _id = '' ; user = { } ; constructor ( private userService , private _message , private router , private route ) { this . route . params . subscribe ( ( params ) => { console . dir ( params ) ; this . _id = params [ 'id' ] || '' ; } ) ; } ngOnInit ( ) { if ( this . _id !== '' ) { this . queryUser ( this . _id ) ; } this . saveUser ( 'uuu' ) ; } saveUser ( name ) { name = name . trim ( ) ; if ( ! name ) { return ; } this . userService . create ( name ) . then ( hero => { this . user = null ; } ) ; } queryUser ( id ) { this . userService . query ( id ) . then ( response => { if ( response . status ) { this . _message . info ( response . message ) ; this . user = response . result ; } else { this . _message . error ( response . message ) ; } } ) ; } }