【发布时间】:2023-03-09 19:06:01
【问题描述】:
我正在尝试添加输入框,下面是我的代码。输入未显示
component.html
<form [formGroup]="formGroup" (validSubmit)="onSubmit()">
<div class="form-group mb-3">
<label class="form-label">Age</label>
<ng-select [items]="ages"
[selectOnTab]="true"
bindValue="value"
labelForId="age"
placeholder="Select age"
formControlName="Age">
</ng-select>
</div>
</form>
组件.ts
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators} from "@angular/forms";
@Component({
selector: 'demo-form-validation',
templateUrl: './basic-validation.html'
})
export class DemoFormBasicValidationComponent implements OnInit {
formGroup: FormGroup;
ages: any[] = [
{ value: '<18', label: 'Under 18' },
{ value: '18', label: '18' },
{ value: '>18', label: 'More than 18' },
];
constructor(private formBuilder: FormBuilder) {}
ngOnInit() {
this.formGroup = this.formBuilder.group({
Age: [null, Validators.required],
});
}
}
app.module.ts
import { NgBootstrapFormValidationModule } from 'ng-bootstrap-form-validation';
import { NgSelectModule } from '@ng-select/ng-select'
import { FormsModule } from '@angular/forms';
@NgModule({
declarations: [
AppComponent
],
imports: [
NgBootstrapFormValidationModule.forRoot(),
NgSelectModule,
FormsModule
],
providers: [
],
bootstrap: [AppComponent]
})
export class AppModule { }
这是我得到的输出。仅显示标签
【问题讨论】:
-
使用 NgSelectModule 你看不到输入,但是当你点击选择时你可以开始写。试试
-
@Guiditox 除了标签之外什么都没有。无法输入任何内容
-
看这个链接一步一步做:npmjs.com/package/@ng-select/ng-select
标签: html angular typescript input dropdown