如何更新angular2中按钮点击的数据?
how to update data on button click in angular2?
我有 notificationService,它包含要在 toast 通知中显示的数据。数据数组的每个元素都包含吐司通知的数据。
export Notification service {
data:Array<NotificationData>;
getData() {
return this.data;
}
}
export class NotificationData {
dismissed:boolean;
}
现在 toast 组件中正在使用数据数组。
export class ToastNotificationComponent implements OnInit {
data: Array<NotificationData>;
constructor(public ns: NotificationService) {
this.data = ns.getData();
}
}
我想在单击按钮时更新已取消的变量。
<div class="toast-container">
<div *ngFor = "let datum of data">
<button (click)= "closeToast($event)" >close</button>
</div>
</div>
如何在此处将视图与 notificationData 绑定?
如果我使用事件绑定,我将无法通过 DOM 节点访问 notificationData。
这里有使用 ngModel 的解决方案吗?
尝试输入:
<按钮(单击)= "data.dismissed = !data.dismissed " >关闭
我有 notificationService,它包含要在 toast 通知中显示的数据。数据数组的每个元素都包含吐司通知的数据。
export Notification service {
data:Array<NotificationData>;
getData() {
return this.data;
}
}
export class NotificationData {
dismissed:boolean;
}
现在 toast 组件中正在使用数据数组。
export class ToastNotificationComponent implements OnInit {
data: Array<NotificationData>;
constructor(public ns: NotificationService) {
this.data = ns.getData();
}
}
我想在单击按钮时更新已取消的变量。
<div class="toast-container">
<div *ngFor = "let datum of data">
<button (click)= "closeToast($event)" >close</button>
</div>
</div>
如何在此处将视图与 notificationData 绑定?
如果我使用事件绑定,我将无法通过 DOM 节点访问 notificationData。 这里有使用 ngModel 的解决方案吗?
尝试输入:
<按钮(单击)= "data.dismissed = !data.dismissed " >关闭