angular - 与 formControlName 一起使用的 Angular 4 Multiselect 插件
问题描述
我正在寻找一个多选插件(即https://www.npmjs.com/package/ng-multiselect-dropdown),但它可以与 formControlName 一起使用。
我有一个属性组件(我希望插件在其中工作),其他组件使用它来创建基于动态表单模板的表单。这就是为什么我不得不使用这个组件。
组件:
import { Component, OnInit, Input } from '@angular/core';
import { FormGroup } from '@angular/forms';
import { Attribute } from '../../models/attribute';
@Component({
selector: 'app-attribute',
templateUrl: './template.html',
styleUrls: ['./style.css']
})
export class AttributeComponent implements OnInit {
@Input() attribute: Attribute;
@Input() form: FormGroup;
@Input() forceReadonly = false;
constructor() { }
ngOnInit() {
}
}
风景 :
<div class="form-group" [formGroup]="form">
<label [attr.for]="attribute.name">{{attribute.displayName}} <span class="mandatory" *ngIf="attribute.required === true">*</span></label>
<div [ngSwitch]="attribute.type">
<input *ngSwitchCase="'TEXT'" type="text" class="form-control" [id]="attribute.name"
[formControlName]="attribute.name"
[readonly]="forceReadonly ? true : attribute.readOnly"
[required]="attribute.required"
/>
<select *ngSwitchCase="'SELECT'" class="form-control" [id]="attribute.name"
[formControlName]="attribute.name" [disabled]="forceReadonly ? true : attribute.readOnly">
<option *ngFor="let opt of attribute.format.values" [value]="opt">{{opt}}</option>
</select>
<select *ngSwitchCase="'MULTISELECT'" class="form-control" [id]="attribute.name"
[formControlName]="attribute.name" multiple="multiple" [disabled]="forceReadonly ? true : attribute.readOnly">
<option *ngFor="let opt of attribute.format.values" [value]="opt">{{opt}}</option>
</select>
</div>
</div>
所以我不能将我的多选组件绑定到一个 ngModel,就像我看到需要的那样。
你能帮帮我吗?
谢谢
解决方案
推荐阅读
- google-chrome - Strange Bug in Chrome 69.0.3497.81 + spring boot security + vaadin when uploading files
- asp.net-mvc - 如何在 Visual Studio 2017 的 .cshtml 文件中展开/折叠?
- python - Python小写列表理解在似乎正确时未能通过测试?
- azure - Azure 函数部署失败,因为 function.json 错误
- python - 为 python 日志添加文件格式化程序
- mysql - phpmyadmin doesn't respond after timeout. What can I do?
- r - What is the standard way to set default paths for function arguments in R packages?
- node.js - Middleware not working for 2nd model i.e doctor but it works fine for admin.Here I am creating a two user model one is admin and one is doctor
- rest - 如何在 restful api 中检查他或她对特定资源的访问?
- android - My android app having google sign in crashes. It takes email and password as input and after that it crashes everytime.