首页 > 代码库 > [Angular2 Form] Create Radio Buttons for Angular 2 Forms
[Angular2 Form] Create Radio Buttons for Angular 2 Forms
Using Radio Buttons in Angular 2 requires a basic understanding of forms as well as how their label
s 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 for
attributes 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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。