当按钮状态为“批准”并且“批准”按钮为“待定”状态时,我想显示“拒绝”按钮。我正确传递了值,但两个按钮始终显示。
这是我的.ts文件
export class NotificationComponent implements OnInit {
notices: notification[] = [];
public approve_show: boolean = false;
public disapprove_show: boolean = false;
constructor(
private http: HttpClient,
private router: Router,
) { }
ngOnInit() {
var url = "http://localhost:3000/notification/view";
this.http.get<any>(url).subscribe(res => {
this.notices = res;
var i = 0;
for (var prop in res) {
if (res.hasOwnProperty(prop)) {
// console.log(res[i].state)
if (res[i].state == 'Approved') {
console.log("approved")
this.disapprove_show = true
}
else {
this.approve_show = true
}
i++;
}
}
}, (err) => {
console.log(err);
});
}
}
这是我的html代码
<button *ngIf="approve_show" mat-raised-button class="approve_btn">Approve</button>
<button *ngIf="disapprove_show" mat-raised-button color="warn" style="width:100px;">Disapprove</button>
由于您将其用于列表,因此请使用以下内容。 <button *ngIf="res.state=='Approved'" mat-raised-button color="warn" style="width:100px;">
问题是您对按钮使用了全局变量。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句