Enable/Disable Angularjs buttons with values coming from the api

Asked

Viewed 886 times

0

I have my following screen : inserir a descrição da imagem aqui

The side menu comes from an Api List with user permissions

have my classes:

public class Menu {

    public int Id {get;set;}
    public string Nome {get;set;}
}
public class Item {
    public int Id {get;set;}
    public string Nome {get;set;}
    public Menu Menu {get;set;}

}
public class Opcao {
    public int {get;set;}
    public string Nome {get;set;}
    public Item Item {get;set;}
}

Where Menu = Register

Item = Client

Option = Include, Edit, Delete, Others...

The side menu listing I got perfectly, just use ng-repeat and ready.

My problem is the Option, how will I play the correct one for that view? to leave enabled / disabled the buttons it has or not permission?

1 answer

1

Since Angularjs does not work with access/permission control, I would use ng-show/ng-Hide depending on how your API data structure comes.

An example would be:

<tr>
   <td ng-show="user.hasPermitionToEdit">Editar</td>
   <td ng-show="user.hasPermitionToDelete">Excluir</td>
</tr>

I hope it helped you.

  • Yes, that’s right, but how do I pass it to the View? because on the menu for example, that’s where it comes the routes......

  • Assuming that you have access to the user (Item) in the construction of the Options (Edit, etc.) and that the Option item is the user you can delete, I would build a function in the type controller isUserPermited(item, option.), returning a boolean if the "session" user is the same as option.item. This way you could check the user in this function, +/- as the example below: $scope.isUserPermited = function(userOnSession, userPermited) {&#xA; // lógica que compara&#xA;}; and its view +/-: <td ng-show="isUserPermited(item, opcao.item)">Editar</td>

  • made sense, I’ll try

Browser other questions tagged

You are not signed in. Login or sign up in order to post.