데이터 구동 각도 응용 프로그램이 있습니다. 토글 된 상태로 전달하는 토글 구성 요소가 있습니다. 내 문제는 개체로 토글 부울을 전달하지 않으면 양방향 데이터 바인딩이 작동하지 않는 것입니다. EventEmitter를 사용하거나 변수를 객체에 전달하지 않고도 this가 작동하도록하려면 이 있습니까? 이것은 재사용 가능한 구성 요소이며 응용 프로그램은 데이터를 많이 사용하므로 값을 옵션이 아닌 객체로 전달합니다. 내 코드Angular2 Component @ Input 양방향 바인딩
toggle.html
<input type="checkbox" [(ngModel)]="toggled" [id]="toggleId" name="check"/>
toggle.component.ts [(toggled)]="..."
당신을 작동하려면
import { Component, Input, EventEmitter, Output } from '@angular/core';
@Component({
moduleId: module.id,
selector: 'toggle-switch',
templateUrl: 'toggle-switch.component.html',
styleUrls: ['toggle-switch.component.css']
})
export class ToggleSwitchComponent {
@Input() toggleId: string;
@Input() toggled: boolean;
}
parent.component.html
<toggle-switch toggleId="toggle-1" [(toggled)]="nongenericObject.toggled"></toggle-switch>
http://stackoverflow.com/documentation/angular2/8943/angular2-input-output#t=201702021650455443161 –