需要PrimeNG下拉在Angular2 模型驱动的表单中的帮助。我发现的PrimeNG文档只使用模板驱动的表单。
以下示例代码将有很大帮助:
谢谢。
发布于 2017-08-04 16:42:10
要在Angular2或Angular4中使用模型驱动的表单,需要将下拉列表更改为
<p-dropdown [options]="cities" formControlName="selectedCity"></p-dropdown>
并在后端实例化一个formGroup,其中包含控件selectedCity,如下所示.
this.angularObjectForm = this.formBuilder.group({selectedCity: [''])}
发布于 2016-07-02 08:00:06
//模板处理
<form id="demoForm" name="demoForm" [ngFormModel]="demoForm" (submit)="demoForm($event, demoForm)"
method="post" action="" autocomplete="off">
<h3 class="first">Demo</h3>
<p-dropdown [options]="cities" [(ngModel)]="selectedCity"></p-dropdown>
<span *ngIf="!selectedCity"> Required </span>
<button pButton [disabled]="!selectedCity" type="submit" (click)="onclick()" label="Click"></button>
</form>
//导入所需的文件
import {Button} from 'primeng/primeng';
import {Dropdown} from 'primeng/primeng';
//类处理
export class MyModel {
cities: SelectItem[];
selectedCity: string;
constructor() {
this.cities = [];
this.cities.push({label:'Moscow', value:'1'});
this.cities.push({label:'Istanbul', value:'2'});
this.cities.push({label:'Berlin', value:'3'});
this.cities.push({label:'Paris', value:'4'});
}
public demoForm(event: Event, demoForm: ControlGroup): void {
event.preventDefault();
// working area //
}
}
发布于 2018-12-17 07:11:10
下面要使用Primeng下拉列表是一个简单的解释::npm -保存
然后将其导入父模块。
import { DropdownModule } from 'primeng/primeng';
@NgModule({
imports: [
DropdownModule
]
});
将以下html代码添加到html文件中:
<p-dropdown
[options]="listVariable"
placeholder="Select"
[(ngModel)]="selectedOption"
(onChange)="onChangeValue()">
这些是实现的基本步骤。我发现了非常简单的实用解释,这里,他解释得很好。
https://stackoverflow.com/questions/38138098
复制相似问题