1

I am getting some compilation error while building the angular project and the error is given below.

Error:

list.component.html(155,47): Property 'auth' is private and only accessible within class 'ListComponent'.

I am explaining my code below.

<td mat-cell *matCellDef="let element; let i = index;">
    <mat-icon *ngIf="auth.currentUserValue.RoleName === 'admin'" (click)="editStore(element)" class="text-primary"
        style="cursor: pointer">edit</mat-icon>
    &nbsp;
    <mat-icon *ngIf="auth.currentUserValue.RoleName === 'admin'" (click)="deleteStore(element)" class="text-danger"
        style="cursor: pointer">delete_forever
    </mat-icon>
</td>
import { AuthenticationService } from 'src/app/_services';
constructor(private auth : AuthenticationService) {}

I need to clear this error.

1 Answer 1

1

The AuthenticationService is marked as private. This means that it cannot be accessed outside of its containing class. Which is the component and not the template.

Solution 1

Mark the AuthenticationService as public.

constructor(public auth : AuthenticationService) {}

This will allow your template to have access to it.

Solution 2

It's advised against to access your services or properties on your services directly from the template. Create a reference on the component instead.

import { AuthenticationService } from 'src/app/_services';

@Component({})
export class MyComponent {
  currentUserRoleName = this.auth.currentUserValue.RoleName;
  constructor(private auth : AuthenticationService) {}
}

Your template:

<td mat-cell *matCellDef="let element; let i = index;">
    <mat-icon *ngIf="currentUserRoleName === 'admin'" (click)="editStore(element)" class="text-primary"
        style="cursor: pointer">
        edit</mat-icon>
    &nbsp;
    <mat-icon *ngIf="currentUserRoleName === 'admin'" (click)="deleteStore(element)" class="text-danger"
        style="cursor: pointer">delete_forever
    </mat-icon>
</td>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.