• [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 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

  • 相关阅读:
    【ImageMagick】ImageMagick命令行工具
    MAC 下安装PIL
    【转】tmux入门指南
    python编码和小数据池
    ----------BMI指数小程序----------
    ----------简单购物车小程序----------
    python基础数据类型3
    python基本数据类型2
    python基本数据类型
    python循环
  • 原文地址:https://www.cnblogs.com/Answer1215/p/5918496.html
Copyright © 2020-2023  润新知