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. lua Date和Time

    time和date两个函数在Lua中实现所有的时钟查询功能.函数time在没有参数时返回当前时钟的数值.(在许多系统中该数值是当前距离某个特定时间的秒数.)当为函数调用附加一个特殊的时间表时,该函数就 ...

  2. java中的Switch case语句

    java中的Switch case 语句 在Switch语句中有4个关键字:switch,case break,default. 在switch(变量),变量只能是整型或者字符型,程序先读出这个变量的 ...

  3. Chapter13:拷贝控制

    拷贝控制操作:拷贝构造函数.拷贝赋值运算符.移动构造函数.移动赋值运算符.析构函数. 实现拷贝控制操作的最困难的地方是首先认识到什么时候需要定义这些操作. 拷贝构造函数: 如果一个构造函数的第一个参数 ...

  4. html5的一些表单属性

    IE8及以下不能很好支持这些属性 <pre>input属性: placeholder:输入框的默认值,向用户显示描述性说明文字或者提示信息 autocomplete:值为on和off..o ...

  5. Python的16个“坑”

    1. 不要使用可变对象作为函数默认值 代码如下: In [1]: def append_to_list(value, def_list=[]): ...: def_list.append(value) ...

  6. 第三百零八至三百二十天 how can I 坚持

    十三天..2月4号至2月16号,好快,假期还没开始就结束了.一一回忆下. 2月4号,腊月二十六,最后一天上班,没多大事,好像是玩了一天,东月回家,貌似路上好折腾,晚上D401,和她聊了一路,也聊了好多 ...

  7. Rdlc报表出现空白页解决方法

    在使用RDLC报表时,碰到这种情况:当只有一页数据时,报表确显示两页,第二页除了报表头之外数据为空.然后,当有多页数据时,最后一页为空. RDLC報表設計好後,在ReportViewer預覽報表時,頁 ...

  8. <一道题>求1 + 2! + 3! + .... + N!

    一道小题,╮(╯▽╰)╭ #include <stdio.h> /*jie cheng * * 1 + 2! + 3! + ... + N! * * */ int factorial(in ...

  9. IIS7 503错误 Service Unavailable

    把相应的Application Pools的process model的Identity属性设置成“LocalSystem”就OK了

  10. oradmin相关用法

    [转]oradmin相关用法 创建例程: -NEW -SID sid | -SRVC 服务 [-INTPWD 口令] [-MAXUSERS 数量] [-STARTMODE a|m] [-PFILE 文 ...