• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Angular5中提取公共组件之radio list的实例代码

angularjs 搞代码 4年前 (2021-12-31) 32次浏览 已收录 0个评论

这篇文章主要介绍了Angular5中提取公共组件之radio list的实例代码,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下

本文给大家说一下Radio List的公共组件提取。

Radio List组件提取起来很方便,不想Checkbox那么复杂。

radio-list.component.ts

 import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core'; import { RadioItem } from '../../model/radio'; import { NgModel } from '@angular/forms'; @Component({ selector: 'app-radio-list', templateUrl: './radio-list.component.html', styleUrls: ['./radio-list.component.css'] }) export class RadioListComponent implements OnInit { @Input() list: RadioItem[]; @Input() name: string; @Input() colNum: number = 6; @Input("selectModel") model: string; @Output("selectChange") onChange: EventEmitter = new EventEmitter(); constructor() { } ngOnInit() { } changeSelected() { let data = { value: this.model, name: this.name }; this.onChange.emit(data); } }

radio-list.component.html

 <div class="form-row"> <div class="col-{{colNum}} mb-2"> <div class="form-check abc-radio abc-radio-primary"> <label class="form-check-label" for="{{name}}_{{item.id}}"> {{item.name}} </label></div></div></div>

在相关引用的module中注册

 import { RadioListComponent } from '../components/radio-list/radio-list.component'; export const routes = [ { path: '', component: xxxComponent, pathMatch: 'full' } ]; @NgModule({ imports: [...], declarations: [... , RadioListComponent , ...], providers: [] }) export class xxxModule { static routes = routes; }

对应的html中引用如下:

  

按照如上步骤,还缺少对应的selectChange($event):

 selectChange(model: any) { this[model.name] <strong style="color:transparent">来源gaodai#ma#com搞@@代~&码网</strong>= model.value; }

总结

以上就是Angular5中提取公共组件之radio list的实例代码的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Angular5中提取公共组件之radio list的实例代码

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址