File
Implements
Metadata
| selector |
app-pettype-add |
| styleUrls |
./pettype-add.component.css |
| templateUrl |
./pettype-add.component.html |
Index
Properties
|
|
|
Methods
|
|
|
Outputs
|
|
|
Methods
|
onSubmit
|
onSubmit(pettype: PetType)
|
|
|
Parameters :
| Name |
Type |
Optional |
| pettype |
PetType
|
No
|
|
import {Component, EventEmitter, OnInit, Output} from '@angular/core';
import {PetType} from '../pettype';
import {PetTypeService} from '../pettype.service';
@Component({
selector: 'app-pettype-add',
templateUrl: './pettype-add.component.html',
styleUrls: ['./pettype-add.component.css']
})
export class PettypeAddComponent implements OnInit {
pettype: PetType;
errorMessage: string;
@Output() newPetType = new EventEmitter<PetType>();
constructor(private pettypeService: PetTypeService) {
this.pettype = {} as PetType;
}
ngOnInit() {
}
onSubmit(pettype: PetType) {
pettype.id = null;
this.pettypeService.addPetType(pettype).subscribe(
newPettype => {
this.pettype = newPettype;
this.newPetType.emit(this.pettype);
},
error => this.errorMessage = error as any
);
}
}
<!--
~ /*
~ * 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.
~ */
-->
<div class="container-fluid">
<div class="container xd-container">
<h2>New Pet Type</h2>
<form id="pettype" class="form-horizontal" (ngSubmit)="onSubmit(pettypeForm.value)" #pettypeForm="ngForm">
<div class="form-group" hidden="true">
<input type="text" hidden="true" class="form-control" id="id" [(ngModel)]="pettype.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)]="pettype.name"/>
</div>
<button class="btn btn-default" type="submit">Save</button>
</div>
</div>
</form>
</div>
</div>
Legend
Html element with directive