国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

Angular5中提取公共組件之radio list的實例代碼

2024-05-06 15:32:49
字體:
供稿:網(wǎng)友

本文給大家說一下Radio List的公共組件提取。

Radio List組件提取起來很方便,不想Checkbox那么復(fù)雜。

radio-list.component.ts

import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';import { RadioItem } from '../../model/radio';import { NgModel } from '@angular/forms';@Component({  selector: 'app-radio-list',  templateUrl: './radio-list.component.html',  styleUrls: ['./radio-list.component.css']})export class RadioListComponent implements OnInit {  @Input() list: RadioItem[];  @Input() name: string;  @Input() colNum: number = 6;  @Input("selectModel") model: string;  @Output("selectChange") onChange: EventEmitter<any> = new EventEmitter<any>();  constructor() { }  ngOnInit() {  }  changeSelected() {    let data = { value: this.model, name: this.name };    this.onChange.emit(data);  }}

radio-list.component.html

<div *ngIf="list" class="form-row">  <div class="col-{{colNum}} mb-2" *ngFor="let item of list">    <div class="form-check abc-radio abc-radio-primary">      <input class="form-check-input" type="radio" [value]="item.id" [(ngModel)]="model" (change)="changeSelected()" name="{{name}}" id="{{name}}_{{item.id}}">      <label class="form-check-label" for="{{name}}_{{item.id}}">        {{item.name}}      </label>    </div>  </div></div>

在相關(guān)引用的module中注冊

import { RadioListComponent } from '../components/radio-list/radio-list.component';export const routes = [  { path: '', component: xxxComponent, pathMatch: 'full' }];@NgModule({  imports: [...],  declarations: [...    , RadioListComponent    , ...],  providers: []})export class xxxModule {  static routes = routes;}

對應(yīng)的html中引用如下:

 <app-radio-list [list]="sourceArr"         [name]="'selectedSource'"         [colNum]="12"        [(selectModel)]="selectedSource"        (selectChange)="selectChange($event)"> </app-radio-list>

按照如上步驟,還缺少對應(yīng)的selectChange($event):

 selectChange(model: any) {   this[model.name] = model.value; }

總結(jié)

以上所述是小編給大家介紹的Angular5中提取公共組件之radio list的實例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對錯新站長站網(wǎng)站的支持!

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 保定市| 沾化县| 扶余县| 河东区| 南丰县| 铜川市| 二连浩特市| 宝应县| 松桃| 巴彦淖尔市| 贺州市| 潼关县| 定边县| 鹤峰县| 新干县| 奉贤区| 天水市| 宁武县| 合阳县| 东辽县| 山东| 昌都县| 万荣县| 绍兴县| 乌鲁木齐县| 沙坪坝区| 福鼎市| 静宁县| 隆子县| 德江县| 九龙城区| 特克斯县| 香河县| 收藏| 城固县| 苍山县| 巴林左旗| 满洲里市| 微山县| 鄄城县| 景洪市|