1

i used Angular 2 to create a web, i want to enable or disable some sidebar components according to user login data, login data of user is stored in json and through a Qwebchannel a token is passed in locolhost for authentication, now what i want is to enable or disable some sidebar component according to user login token...

ReDirectToNextPage(user: string){
    setTimeout(function () {
        location.reload();
    }, 1);
    console.log('ReDirectToNextPage called from JS');
    this.tokenStorage.saveToken("login#username:" + user);
    this.router.navigate(['server-config']);
}
checkLogin() {

    if (this.tokenStorage.getToken() != undefined && this.tokenStorage.getToken() != null && this.tokenStorage.getToken().indexOf("login") != -1) {
        this.router.navigate(['server-config']);
    } else {
        const card = document.getElementsByClassName('card')[0];
        setTimeout(function () {
            card.classList.remove('card-hidden');
        }, 700);
    }
}

this is what i tried i am getting token for loggedIN user i want to show only assign rights to loggedIN user (rights vary from user login) Thanks

R. Richards
  • 24,603
  • 10
  • 64
  • 64
ellenkis
  • 137
  • 7

1 Answers1

0

I haven't worked a lot with angular 2 but I suggest start working with angular 6+ which covers typescript , but what you need is common , ngIf example with angularjs :

<div *ngIf="isValid"> Data is valid. </div> 

Tutorial

and same solution in stackoverflow angular 2 ngIf

If you wanted to disable it this can help you : deactive angular button

so for example you have a jwt so you can use a boolean to check if user is authenticated or not I hope this will help you ;)

A.Risheh
  • 73
  • 8
  • what i want is like if user login s/he will get limited sidebar components but admin can get all of the sidebar components as it is already described in a JSON file which states the rights of user now i want to get that data from QWEBCHANNEL into my angular project. – ellenkis Sep 14 '19 at 09:48
  • can you give sample json its like havePermission["option1"] : myJson["option1"] == 1 and use it on ngIf – A.Risheh Sep 14 '19 at 10:48
  • i want solve this in typescript(.TS) file instead of HTML – ellenkis Sep 14 '19 at 12:20
  • maybe something like this : template = "
    option1
    " or "
    option2
    " and use {{template}} :D , I don't think this way is optimal
    – A.Risheh Sep 14 '19 at 13:03