【发布时间】:2021-01-27 04:36:58
【问题描述】:
在我的组件中,我需要在 Angular 表单上显示为下拉列表的 2 个字符串,我正在努力获取 HTML 页面上的值
演示 - https://stackblitz.com/edit/angular-dc4s7d?file=src%2Fapp%2Fapp.component.ts
这是我的 ts 代码
export class EmployeeComponent implements OnInit {
constructor(public employeeService: EmployeeService) {}
public listItem: string[];
ngOnInit() {
this.listItem = ["A", "B"]; ----->>>>> Dropdown values
}
HTML代码
<div class="m-3 input-group; padding:10px; color:red; border: 3px solid ">
<span class="input-group-text">Type</span>
<select type="text" name="type" #type="ngModel"
[(ngModel)]="employeeService.selectedEmployee.type "placeholder="Type">
<option *ngFor="let dl of listItem" [value]="dl">{{dl}}</option>
</select>
</div>
【问题讨论】:
-
嘿,请检查我的新更新。它应该工作。请检查并尝试并告诉我。最好的祝愿。 :)
-
employeeService.selectedEmployeeTS 文件中没有名为employeeService.selectedEmployee的属性。这是主要错误并检查控制台。你会发现错误。如果您解决了这些错误,您的代码将起作用。
标签: html angular drop-down-menu