子组件TS
<Button
android:id="@+id/login_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/fragment_login_login_button"
android:theme="@style/AccentButton"/>
父组件HTML:
import { Component, OnInit, Input, Output } from '@angular/core';
import { EventEmitter } from 'events';
export class ChildComponent implements OnInit {
@Output() OpenScheduleCall = new EventEmitter<boolean>();
onLog() {
this.OpenScheduleCall.emit(false);
}
}
我在子组件中设置值,但更改未反映在父组件
中答案 0 :(得分:5)
您尚未将OpenScheduleCall
标记为子组件的输入,因此首先您需要这样做。要在框中实现与香蕉的双向绑定,您的@Output
必须是@Input
变量名称,后缀为Change
。因此,首先将变量OpenScheduleCall
标记为@Input
为子项,然后更改@Output
变量的名称:
export class ChildComponent implements OnInit {
@Input() OpenScheduleCall;
@Output() OpenScheduleCallChange = new EventEmitter<boolean>();
onLog() {
this.OpenScheduleCallChange.emit(false);
}
}
现在你有双向绑定:
[(OpenScheduleCall)]="OpenScheduleCall"
答案 1 :(得分:4)
只有Output
无法进入双向数据绑定。在有界函数的末尾添加()
。
(OpenScheduleCall)="YourFunctionInParent($event)"