So I've variable isAdmin set to true in ngOnInit. This variable is used in one function in same component, only once, to compare if user is admin. In function, variable 'this.isAdmin' is somehow undefined. I tested it solid, before starting function, it have value. Function "showOnlyMultipleOrdersDetails" is activated from html component.

<ng-template kendoGridDetailTemplate  let-dataItem [kendoGridDetailTemplateShowIf]="showOnlyMultipleOrdersDetails">

As workaround I just done this:

<div *ngIf="isAdmin || isTransport"></div>
    <ng-template kendoGridDetailTemplate  let-dataItem [kendoGridDetailTemplateShowIf]="showOnlyMultipleOrdersDetails">

And it works as it should, but I'm really curious why function doesn't see this variable. Someone had similar problem ?

I thought this situation was because of subscription, so I set this boolean variable by Promise, but still, in the function this.isAdmin is undefined (even if I defined it as false in variable declarations!), also I thought somehow this variable is overwritten but no. Using other functions this.isAdmin is set properly. Maybe it's because of this kendoGridDetailTemplate , [kendoGridDetailTemplateShowIf].

1

There are 1 best solutions below

1
On

How did you define your function?

Because if you did define it via an arrow function then this might not refer to the object where isAdmin is available but to the calling object of the function...