I created a component for processing the selection window, now when I put it in the form tag after the submitted form, the selection result is not displayed in the console.
What is the problem with my code? how can i fix this?
- testOption: an array of objects that I passed, selected a select box using
@Input .
Here is the component of the selection window:
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;
Usage in html:
<input-select label="test" name="select2" [options]="testOption"></input-select>
html form:
<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: (no selection window value)
Object {name: "test", building-type: "tset" }
Sajad source share