在使用TypeScript的Angular 5应用程序中.当尝试实现组件之间的通信时,我遇到了称为循环依赖的问题.
有两个分量无线电和无线电组:
有两个分量无线电和无线电组:
<radio-group [(value)]='selected'> <radio value='1'></radio> <radio value='2'></radio> <radio value='3'></radio> </radio-group>
当用户选择和取消选择项目时,它们彼此通信.
组件实现示例
RadioGroupComponent:
import { Component,forwardRef,Input,Optional,ContentChildren,QueryList,EventEmitter,Output,ChangeDetectorRef,ChangeDetectionStrategy,AfterContentInit,OnChanges } from '@angular/core'; import { RadioGroup } from './radio-group.component'; @Component({ selector: 'radio',styles: [`:host{cursor:pointer;}`],template: `<div (click)='check()'> <span *ngIf='!checked'>⚪️</span> <span *ngIf='checked'>