我試圖創建角2的應用程序,並在我的應用程序有一個身份驗證服務,我的HTML模板是財產以後這樣的:爲什麼* ng在角2中總是在使用函數時執行?
<header>
<div *ngIf="isLogin()"><a href="">profile</a></div>
<div *ngIf="!isLogin()"><a href="">register</a></div>
<div *ngIf="!isLogin()"><a href="">signin</a></div>
</header>
**and this is my class :**
@Component({
selector: 'main-menu',
templateUrl: '/client/tmpl/menu.html',
directives: [ROUTER_DIRECTIVES]
})
export class Menu extends Ext {
public items: any;
constructor(private _util: UtilService, private _user: UserService) {
super();
}
public isLogin() {
console.log("test"); <==== my problem is here
return this._user.authorized();
}
}
一直是我的職能在執行時(在我的身份驗證服務,我有另一個功能,他們也runing)!這是使用裏面的函數* ngif ?? !!! 我擔心我的資源,我想知道它的問題與否?
你想要做什麼?顯然你的函數必須每次調用,因爲它在視圖上綁定了綁定,所以每次角度檢查isLogin中的任何變化。 –
這就像setinterval或無限循環! –
請你能改寫你的文章,這是不可理解的。 – Romain