I created a component for handling select box, now when I put it in form tag after submitted form the result of the selection doesn't show up in console.
What's the problem with my code? how can I fix this?
- testOption: is array of object I passed throw the select box with
@Input
.
here is select box component:
import { Component, OnInit, Input } from '@angular/core';
@Component({
selector: 'input-select',
template:`
<div class="field-select">
<span><icon name="select-arrow" size="10"></icon></span>
<select name="{{name}}" class="field">
<option value="0" disabled selected>{{label}}</option>
<option *ngFor="let option of options" [ngValue]="option.value">{{option.name}}</option>
</select>
</div>
`
})
export class InputSelectComponent implements OnInit {
@Input() label: string;
@Input() name: string;
@Input() options;
// testOptions = [
// {value:'test',name:'test2'},
// {value:'test',name:'test2'}
// ];
constructor() { }
ngOnInit() {
console.log(this.options);
}
}
Usage in html:
<input-select label="test" name="select2" [options]="testOption"></input-select>
form html:
<form role="form" class="form" #f="ngForm" (ngSubmit)="onSubmit(f)">
<input class="field" name="name" ngModel type="text" placeholder="n1">
<input-select label="b2" name="select2" [options]="testObject"></input-select>
<input class="field" name="building-type" type="text" ngModel placeholder="b3">
</form>
console log: (there is no select box value)
Object {name: "test", building-type: "tset" }
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…