>我有通知服务,其中包含要在 toast 通知中显示的数据。数据数组的每个元素都包含 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>
如何在此处将视图与通知数据绑定?
如果我使用事件绑定,我将无法通过 DOM 节点访问通知数据。 这里有使用 ngModel 的解决方案吗?
尝试输入以下内容:
<按钮(单击(>关闭