本文给大家说一下Radio List的公共组件提取。
Radio List组件提取起来很方便,不想Checkbox那么复杂。
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= new EventEmitter (); constructor() { } ngOnInit() { } changeSelected() { let data = { value: this.model, name: this.name }; this.onChange.emit(data); } }