so im trying to Bind the selected Item of a Dropdown to a Property with 2 way binding but the property in my typescript code always stays the same.
This is my Select Tag:
<select #select class="form-control" id="favouriteValue" ([ngModel])="selectedValue">
<option *ngFor="let value of valuesFromHomeComp" [ngValue]="value">{{value.name}}</option>
</select>
this is my component:
import { Component, OnInit, Input } from '@angular/core';
@Component({
selector: 'app-register',
templateUrl: './register.component.html',
styleUrls: ['./register.component.css']
})
export class RegisterComponent implements OnInit {
model: any = {};
@Input()valuesFromHomeComp: any[];
selectedValue: any;
constructor() {}
ngOnInit() {
this.selectedValue = this.valuesFromHomeComp[0];
}
}
You're using ([ngModel])
should be [(ngModel)]
. cheers.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.