上一篇说到了Checkbox 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<any> = new EventEmitter<any>(); constructor() { } ngOnInit() { }
changeSelected() {
let data = { value: this.model, name: this.name };
this.onChange.emit(data);
}
}

radio-list.component.html

 <div *ngIf="list" class="form-row">
<div class="col-{{colNum}} mb-2" *ngFor="let item of list">
<div class="form-check abc-radio abc-radio-primary">
<input class="form-check-input" type="radio" [value]="item.id" [(ngModel)]="model" (change)="changeSelected()" name="{{name}}" id="{{name}}_{{item.id}}">
<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中引用如下:

 <app-radio-list [list]="sourceArr"
[name]="'selectedSource'"
[colNum]="12"
[(selectModel)]="selectedSource"
(selectChange)="selectChange($event)">
</app-radio-list>

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

 selectChange(model: any) {
this[model.name] = model.value;
}

Angular5中提取公共组件之radio list的更多相关文章

  1. Angular5中提取公共组件之checkbox list

    因为工作原因,需要使用到checkbox list多选项功能. 一直在尝试在checkbox组件中添加NgModel的属性,但是只能在单个checkbox复选框上使用,checkbox list就没办 ...

  2. webpack学习笔记--提取公共代码

    为什么需要提取公共代码 大型网站通常会由多个页面组成,每个页面都是一个独立的单页应用. 但由于所有页面都采用同样的技术栈,以及使用同一套样式代码,这导致这些页面之间有很多相同的代码. 如果每个页面的代 ...

  3. webpack 多页面支持 & 公共组件单独打包

    webpack - 多页面/入口支持 & 公共组件单独打包 webpack系列目录 webpack 系列 一:模块系统的演进 webpack 系列 二:webpack 介绍&安装 we ...

  4. webpack 多页面|入口支持和公共组件单独打包--转载

    转载自:http://www.jb51.net/article/117490.htm 本篇主要介绍:如何自动构建入口文件,并生成对应的output:公共js库如何单独打包. 多入口文件,自动扫描入口. ...

  5. 一个技术汪的开源梦 —— 基于 .Net Core 的公共组件之 Http 请求客户端

    一个技术汪的开源梦 —— 目录 想必大家在项目开发的时候应该都在程序中调用过自己内部的接口或者使用过第三方提供的接口,咱今天不讨论 REST ,最常用的请求应该就是 GET 和 POST 了,那下面开 ...

  6. Net Core 的公共组件之 Http 请求客户端

    Net Core 的公共组件之 Http 请求客户端 想必大家在项目开发的时候应该都在程序中调用过自己内部的接口或者使用过第三方提供的接口,咱今天不讨论 REST ,最常用的请求应该就是 GET 和 ...

  7. SSIS中循环遍历组件[Foreach Loop Container]

    背景 每月给业务部门提取数据,每个分公司都要提取一般,先跑SQL,再粘贴到Excel中,然后发邮件给相关的人员.费时费力,还容易粘贴错位.因此,需要通过一个程序完成这些步骤.我首先想到的是通过SSIS ...

  8. Vue(三十)公共组件

    以 分页 组件为例:(根据自己具体业务编写) 1.pagination.vue <template> <!-- 分页 --> <div class="table ...

  9. Vue(小案例_vue+axios仿手机app)_公共组件(路由组件传参)

    一.前言                    1.公共轮播图的实现                    2.组件传参,公共组件的实现 二.主要内容 1.公共轮播图的实现 (1)分析:当渲染不同的轮 ...

随机推荐

  1. SPSS学习系列之SPSS Statistics(简称SPSS)是什么?

    不多说,直接上干货! IBM SPSS Statistics 为业务经理和分析人员提供解决基本业务和研究问题所需的核心统计过程.该软件提供的工具使用户能够快速查看数据.为其他测试拟定假设情况.执行澄清 ...

  2. 安装Ubunutu音频视频库

    sudo apt-get install ubuntu-restricted-extras

  3. css3圆形轨迹动画

    <!doctype html>      <html lang="en">      <head>          <meta char ...

  4. Java时间的使用

    JAVA处理日期时间常用方法: 1.java.util.Calendar Calendar 类是一个抽象类,它为特定瞬间与一组诸如 YEAR.MONTH.DAY_OF_MONTH.HOUR 等 日历字 ...

  5. VS设置护眼色

    打开vs2013 选项 环境...如图所示

  6. 引入第三方js文件,报错

    错误:Mixed Content: The page at 'https://localhost:44336/MENU' was loaded over HTTPS, but requested an ...

  7. 三、spark简介

    一.简介 spark的官网:http://spark.apache.org/ spark解决了什么问题? 我们都知道hadoop,hadoop以一个非常容易使用的编程模型解决了大数据的两大难题: 1) ...

  8. Mybatis之简单注解

    Mybatis使用注解实现主键自增长: oracle: @SelectKey(statement="select my_seq.nextval from dual",resultT ...

  9. hadoop start-all.sh报错JAVA_HOME is not set and could not be found.

    原文 错误:JAVA_HOME is not set and could not be found,可能是因为JAVA_HOME环境没配置正确,还有一种情况是即使各结点都正确地配置了JAVA_HOME ...

  10. Java 基础:数组

    一.数组声明: int[] x; int x[]; 在Java中一般使用前者,机把int[]看做一个类型,C++中只能后者 二.数组初始化: 直接提供值: int[] x = {1, 3, 4}; i ...