0
我有一個自定義組件角2個ngmodel自定義下拉
import { Component, OnInit } from "@angular/core";
import { EmploymentType } from './employmenttype.model';
import { EmploymentTypeService } from "../employmenttype/employmenttype.service";
@Component({
selector: 'employmenttype-dropdown',
templateUrl: 'employmenttype-dropdown.html'
})
export class EmploymentTypeDropdownComponent implements OnInit {
selectedEmploymentType:EmploymentType = new EmploymentType('None',0,0);
employmentTypes = [];
constructor(private employmentTypeService: EmploymentTypeService){
}
ngOnInit() {
this.employmentTypeService.getEmploymentTypes()
.subscribe(
(employmentTypes: EmploymentType[]) => {
this.employmentTypes = employmentTypes;
}
);
}
}
,這裏是模板
<select class="form-control" required="required" name="employment-type">
<option *ngFor="let employmenttype of employmentTypes" value={{employmenttype.id}}>
{{employmenttype.name}}
</option>
</select>
我想在這樣的父組件使用它:
<employmenttype-dropdown ([ngModel])="employee?.employmentType" ></employmenttype-dropdown>
但它不起作用。請幫助
http://stackoverflow.com/ questions/34948961/angular-2-custom-form-input,http://blog.thoughtram.io/angular/2016/07/27/custom-form-controls-in-angular-2.html,http:// almerosteyn.com/2016/04/linkup-custom-control-to-ngcontrol-ngmodel –
@GünterZöchbauer感謝您的鏈接 – aldo