@angular/cli项目构建--Dynamic.Form(2)
form-item-control.service.ts update
@Injectable()
export class FormItemControlService {
constructor(private formBuilder: FormBuilder) {
} toFormGroup(formItems: FormItemBase<any>[]) {
const group: any = {};
formItems.forEach(formItem => {
group[formItem.key] = formItem.required
? [formItem.value || '', Validators.required]
: [formItem.value || ''];
});
return this.formBuilder.group(group);
}
}
dynamic-form.component update
<div [formGroup]="form">
<label [attr.for]="formItem.key">{{formItem.label}}</label>
<div [ngSwitch]="formItem.controlType"> <input *ngSwitchCase="'textBox'" [formControlName]="formItem.key"
[id]="formItem.key" [type]="formItem.type" maxlength="{{formItem.maxLength}}"> <select [id]="formItem.key" *ngSwitchCase="'dropDown'" [formControlName]="formItem.key">
<option *ngFor="let opt of formItem.options" [value]="opt.key">{{opt.value}}</option>
</select> <div *ngFor="let opt of formItem.radioOptions">
<input *ngSwitchCase="'radio'" [formControlName]="formItem.key"
[id]="opt.key" type="radio" [value]="opt.key">
<label [attr.for]="opt.key">{{opt.value}}</label>
</div> <div *ngFor="let opt of formItem.checkOptions">
<input *ngSwitchCase="'checkbox'" [formControlName]="formItem.key"
[id]="opt.key" type="checkbox" [value]="opt.key">
<label [attr.for]="opt.key">{{opt.value}}</label>
</div> </div> <!--<div class="errorMessage" *ngIf="!isValid && form.get(formItem.key).touched">{{formItem.label}} is required</div>-->
<div class="errorMessage"
*ngIf="form.get(formItem.key).hasError('required') && form.get(formItem.key).touched">
{{formItem.label}} is required
</div>
</div>
@angular/cli项目构建--Dynamic.Form(2)的更多相关文章
- @angular/cli项目构建--Dynamic.Form
导入所需模块: ReactiveFormsModule DynamicFormComponent.html <div [formGroup]="form"> <l ...
- @angular/cli项目构建--组件
环境:nodeJS,git,angular/cli npm install -g cnpm --registry=https://registry.npm.taobao.org cnpm instal ...
- @angular/cli项目构建--modal
环境准备: cnpm install ngx-bootstrap-modal --save-dev impoerts: [BootstrapModalModule.forRoot({container ...
- @angular/cli项目构建--路由2
app.module.ts update const routes: Routes = [ {path: '', redirectTo: '/home', pathMatch: 'full'}, {p ...
- @angular/cli项目构建--路由1
app.module.ts import {BrowserModule} from '@angular/platform-browser'; import {NgModule} from '@angu ...
- @angular/cli项目构建--animations
使用方法一(文件形式定义): animations.ts import { animate, AnimationEntryMetadata, state, style, transition, tri ...
- @angular/cli项目构建--interceptor
JWTInterceptor import {Injectable} from '@angular/core'; import {HttpEvent, HttpHandler, HttpInterce ...
- @angular/cli项目构建--路由3
路由定位: modifyUser(user) { this.router.navigate(['/auction/users', user.id]); } 路由定义: {path: 'users/:i ...
- @angular/cli项目构建--httpClient
app.module.ts update imports: [ HttpClientModule] product.component.ts import {Component, OnInit} fr ...
随机推荐
- 《Python机器学习》笔记(六)
模型评估与参数调优实战 基于流水线的工作流 一个方便使用的工具:scikit-learn中的Pipline类.它使得我们可以拟合出包含任意多个处理步骤的模型,并将模型用于新数据的预测. 加载威斯康星乳 ...
- 剑指offer 面试49题
面试49题: 题:丑数 题目:把只包含因子2.3和5的数称作丑数(Ugly Number).例如6.8都是丑数,但14不是,因为它包含因子7. 习惯上我们把1当做是第一个丑数.求按从小到大的顺序的第N ...
- Linux基础系列:常用命令(2)
作业一: 1) 新建用户natasha,uid为1000,gid为555,备注信息为“master” groupadd -g 555 natasha useradd -u 1000 -g 555 -c ...
- 【鸟哥的Linux私房菜】笔记1
Linux是什么 从操作系统与cpu架构关系到linux Richard Mathew Stallman GPL 关于GNU计划 Linux的发展 Linux的核心版本 Linux的特色 Linux ...
- 【鸟哥的Linux私房菜】笔记
操作系统核心的功能! 驱动程序与操作系统的关系 2. [计算机组成之组件] 3.CPU实际要处理的数据完全来自于主存储器,这是一个很重要的概念! 4.CPU是整个计算机系统最重要的部分,那么目前世界上 ...
- 获取本地IP并设置到QLineEdit中
#include <QHostAddress> #include <QNetworkInterface> #include <QHostInfo> QString ...
- Grafana连接Prometheus监控Docker平台
Grafana是一款开源的分析平台. Grafana allows you to query, visualize, alert on and understand your metrics no m ...
- shell中嵌套执行expect命令实例(利用expect实现自动登录)
expect是 #!/bin/bashpasswd='123456'/usr/bin/expect <<EOFset time 30spawn ssh root@192.168.76.10 ...
- java 监控命令
jps 查找java所有进程及对应pid -v 列出启动参数 有些默认的参数,使用-v是看不到的,需要执行如下: jcmd pid VM.flags jstack pid 查看该进程的堆栈信息 找到进 ...
- 加和求不同的组合方式数目(dp)
描述 有n个正整数,找出其中和为t(t也是正整数)的可能的组合方式.如: n=5,5个数分别为1,2,3,4,5,t=5: 那么可能的组合有5=1+4和5=2+3和5=5三种组合方式. 输入 输入的第 ...