我有用戶對象,我訂閱。如果用戶等於某個名稱,則不應顯示按鈕。我不知道爲什麼它不會影響html中的ngIf。ngOnInit varible change爲什麼不影響角度爲2/4的html?
我的HTML
<input *ngIf = "showDelete" type = "button" (click) =
"deleteCustomer(customer._id)" value = "Delete" class = "btn btn-danger">
我ngOnInit在appcomponent.ts
ngOnInit() {
let showDelete:boolean =true;
this.authService.getProfile().subscribe(profile => {
this.username = profile.user.name
if (this.username=="admin"){
showDelete=false;
}
},
如果我CONSOLE.LOG的this.username並顯示刪除我得到的預期值,但不改變html中的邏輯
只需移動'showDelete'變量之外你的'ngOnInit()'函數由你組成 –
謝謝!!!!!!! – harryd