我试图创建角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