1

I have 2 users: admin and super admin. And both of them have same menu but different content.

Any idea what the best approach to make their view?. Right now i'm using ng-hide and check for his id. But more content will be messy.

Is there a good way to make it less messy and better approach?

2
  • 1
    You can create a separate partial view for each and conditionally use ng-include to use one or another, or use ng-show/ng-if like you have been doing. Commented Dec 18, 2015 at 12:52
  • yeah, looks like i'm going with ng-include. it make more structural. Commented Dec 19, 2015 at 1:52

2 Answers 2

1

The clean code way: Just because the menu is different you should not make an angular controller for each role.

You should create a object, which provides the menue items for every user. The angular part should be just rendering the information provided by the other object.

Sign up to request clarification or add additional context in comments.

Comments

1

That's a typical issue, that you have to solve on the server side, but if you want to do it on the frontend, I would suggest to get the menu from server, with properly set right properties.

Your model will get it and store it in your model, something like:

$http.get('http://rest-server/menu')
    .success(function (data) {
        $scope.my.menu;
});

The menu will provide the content (click on a menu item -> get allowed services from a defined REST-API) for the certain user (admin/superadmin/whatever).

If you want to implement it completely at the frontend, someone with technical background can easly override your rules.

EDIT: If it is going only about showable content you can use ng-if, ng-show, ng-hide, there are plenty of examples at stackoverflow.

1 Comment

sorry but it's not the menu, but the content. the menu is identical so i'm not using api. Thanks

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.