Using Radio Buttons in Angular 2 requires a basic understanding of forms as well as how their labels will match up with each input. This lesson shows how to use *ngFor with radio buttons and covers the quirks of the id property and forattributes as well as how to style validation of radio buttons.

  <!-- Radio button-->
<form action="" name="myFom4" #myForm4="ngForm">
<div *ngFor="let location of locations">
<input type="radio"
name="location"
ngModel
[value]="location"
[id]="location"
required
>
<label [attr.for]="location">{{location}}</label>
</div>
</form>
<pre>
{{myForm4.value | json}}
</pre>
input.ng-invalid + label:after {
content: '<--Requried to selet one'
}
import {Component, OnInit} from '@angular/core';

@Component({
selector: 'app-message',
templateUrl: './message.component.html',
styleUrls: ['./message.component.css']
})
export class MessageComponent implements OnInit { locations: Array<string>; constructor() {
} ngOnInit() {
this.locations = [
'China',
'Finland',
'Norway',
'Japan'
];
}
}

Github

[Angular2 Form] Create Radio Buttons for Angular 2 Forms的更多相关文章

  1. [Angular2 Form] Use RxJS Streams with Angular 2 Forms

    Angular 2 forms provide RxJS streams for you to work with the data and validity as it flows out of t ...

  2. [Angular2 Form] Create and Submit an Angular 2 Form using ngForm

    Forms in Angular 2 are essentially wrappers around inputs that group the input values together into ...

  3. [Angular2 Form] Build Select Dropdowns for Angular 2 Forms

    Select Dropdowns in Angular 2 a built with select and option elements. You use *ngFor to loop throug ...

  4. [Angular2 Form] Create custom form component using Control Value Accessor

    //switch-control component import { Component } from '@angular/core'; import { ControlValueAccessor, ...

  5. [Angular2 Form] Angular 2 Template Driven Form Custom Validator

    In this tutorial we are going to learn how we can also implement custom form field validation in Ang ...

  6. JSF 2 radio buttons example

    In JSF, "h:selectOneRadio" tag is used to render a set of HTML input element of type " ...

  7. Reading CheckBoxes and Radio Buttons

    Input tags with the type attribute checkbox can be grouped like radio buttons so that several checkb ...

  8. Create CSS3 Buttons Compatible with All Browsers

    Create CSS3 Buttons Compatible with All Browsers http://www.ourtuts.com/create-css3-buttons-compatib ...

  9. mfc Radio Buttons

    添加单选按钮 关联变量 调试宏TRACE BOOL类型 一.添加一组单选按钮 二.添加第二组单选按钮 三.关联变量 四.单选按钮运用 void CMY_Dialog::OnBnClickedButto ...

随机推荐

  1. C使用FILE指针文件操作

    文件的基本概念 所谓“文件”是指一组相关数据的有序集合. 这个数据集有一个名称,叫做文件名.实际上在前面的各章中我们已经多次使用了文件,例如源程序文件.目标文件.可执行文件.库文件 (头文件)等.文件 ...

  2. linux 条件变量

    互斥量就是一把锁,在访问数据时能保证同一时间内只有一个线程访问数据,在访问完以后再释放互斥量上的锁. 条件变量是利用线程间共享的全局变量进行同步的一种机制,主要包括两个动作:一个线程等待"条 ...

  3. BITED数学建模七日谈之四:数学模型分类浅谈

    本文进入到数学建模七日谈第四天:数学模型分类浅谈 大家常常问道,数学模型到底有哪些,分别该怎么学习,这样能让我们的学习有的放矢,而不至于没了方向.我想告诉大家,现实生活中的问题有哪些类,数学模型就有哪 ...

  4. 各种边框样式。。本以为border不是这么用的。

    关于文本框样式□ 文本框样式 □ 显示虚线边框的文本框(IE5.5才可看到效果)  <INPUT style="border-width: 1px,1px,1px,1px;border ...

  5. Python 代码性能优化技巧(转)

    原文:Python 代码性能优化技巧 Python 代码优化常见技巧 代码优化能够让程序运行更快,它是在不改变程序运行结果的情况下使得程序的运行效率更高,根据 80/20 原则,实现程序的重构.优化. ...

  6. Hibernate理论

    1.什么是Hibernate? Hibernate是数据持久层的一个轻量级框架.数据持久层的框架有很多比如:iBATIS,myBatis,Nhibernate,Siena等等.并且Hibernate是 ...

  7. 关于“未使用GUID分区表”无法安装的解决方案

    原帖链接:http://itc.do-johodai.ac.jp/~s0823612/ 原版的Mac不能安装在mbr分区.必须得用GUID分区,其实装在mbr也可以,需要修改两个文件一个是OSInst ...

  8. TCP三次握手及四次挥手详细图解(未完)

    TCP是主机对主机层的传输控制协议,提供可靠的连接服务,采用三次握手确认建立一个连接: (完成三次握手,客户端与服务器开始传送数据) 所谓三次握手(Three-way Handshake),是指建立一 ...

  9. class DelegatingFilterProxy

    /** * Proxy for a standard Servlet Filter, delegating to a Spring-managed bean that * implements the ...

  10. sqlserver 自增字段修改为普通主键字段

    --增加备份字段alter Table tableName add columnNameBak bigint ; --将主键自增字段 赋值到备份字段update tableNameset column ...