我希望在按钮状态为“approve”时显示“不批准”按钮,在“pending”状态下显示“批准”按钮。我已经正确传递了值,但两个按钮总是同时显示。
这是我的.ts文件:
这是我的HTML代码。
这是我的.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>
!
。 - Sagar Vapprove_show
设置为true,而对于其他属性,则设置为disapprove_show
为true。 - Nithin Kumar Biliya