@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 ...
随机推荐
- CentOS Linux中zip压缩和unzip解压缩命令详解
以下命令均在/home目录下操作cd /home #进入/home目录1.把/home目录下面的mydata目录压缩为mydata.zip zip -r mydata.zip myda ...
- springboot springmvc 支持 https
Spring Mvc和Spring Boot配置Tomcat支持Https 背景 最近在项目开发中需要让自己的后端Restful接口支持https,在参考了很多前辈们的博客后总结了一些. Spring ...
- 顽石系列:Linux基础笔试
顽石系列:Linux基础笔试 系统操作 压缩文件 扩展名 压缩程序 *.Z compress *.zip zip *.gz gzip *.bz2 bzip2 *.xz xz *.tar tar 程序打 ...
- ibatis工作原理
摘要: iBATIS 通过 SQL Map 将 Java 对象映射成 SQL 语句和将结果集再转化成 Java 对象,与其他 ORM 框架相比,既解决了 Java 对象与输入参数和结果集的映射,又能够 ...
- offsetLeft与style.left的区别
参考:http://www.cnblogs.com/woshilee/articles/1951457.html offsetLeft 获取的是相对于父对象的左边距 left 获取或设置相对于 具有定 ...
- 通过ip得到所在城市,以及城市所在经纬度坐标(监控系统中用的该代码,小航哥)
监控系统中就是利用的该段代码,实现通过ip得到所在城市,以及城市所在经纬度坐标,最后得以利用echarts实现模拟迁移的效果 api官方介绍: http://lbsyun.baidu.com/inde ...
- volume不能挂载mysql permission denied问题
参考 把玩jenkins docker镜像遇到的volume权限问题 docker run -d -v /root/jenkins:/var/jenkins_home -u 0 -P --name j ...
- 如何选择合适的Linux系统进行桌面程序开发?
32 or 64 ? 众所周知,64位的Windows系统可以近乎完美地运行32位的应用程序,微软出于商业考虑做了这样一个兼容层.而Linux系统则划分的很清楚,默认情况下64位的Linux系统无法运 ...
- 容器排序之sort,stable_sort
bool isShorter(const string &s1, const string &sz){ return s1.size() < sz.size(); } int m ...
- ggplot2学习总结