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. jQuery对select标签的常用操作

    1.获取当前选中项的value. $("#selector").val(); 2.获取当前选中项的text. $("#selector").find(" ...

  2. 从date中获取相应信息

    创建测试用表: CREATE OR REPLACE VIEW v AS SELECT TO_DATE('2015-5-5 13:14:15', 'YYYY-MM-DD HH24:MI:SS') AS ...

  3. 《Windows程序设计第5版》学习进度备忘

    书签:另外跳过的内容有待跟进 __________________学习资源: <Windows程序设计第5版珍藏版> __________________知识基础支持: _________ ...

  4. win7 下启动mysql

    1.下载mysql最新版,解压,不用安装. 2.启动服务: 进入bin文件夹下,使用管理员权限运行 mysqld.exe. 3.测试是否启动了服务. 4.登录mysql.初次安装的,没有设置密码,直接 ...

  5. Map/Reduce中Join查询实现

    张表,分别较data.txt和info.txt,字段之间以/t划分. data.txt内容如下: 201001    1003    abc 201002    1005    def 201003  ...

  6. FbinstTool万能启动超级简单教程

    转载自http://bbs.wuyou.com/forum.php?mod=viewthread&tid=156383 秒到1分钟时间.如果你导入的是超过几百M以上的文件,相对的等待时间会更长 ...

  7. 挖坟之Spring.NET IOC容器初始化

    因查找ht项目中一个久未解决spring内部异常,翻了一段时间源码.以此文总结springIOC,容器初始化过程. 语言背景是C#.网上有一些基于java的spring源码分析文档,大而乱,乱而不全, ...

  8. jszs 枚举算法

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  9. C# Devexpress学习--LabelControl

    A LabelControl can display an image (regular or animated GIF file). Different images can be provided ...

  10. C# Control 控件DrapDrop不触发的问题

    今天在做一个鼠标拖拽功能时,需要用到PictureBox的拖拽,即拖拽一个图标到PictureBox上实现加载绘制,可是怎么整也触发不了DrapDrop事件,最后终于找到了解决方法:原来需要在Drog ...