mikemclin / angular-acl

Role-based permissions for AngularJS
196 stars 49 forks source link

Create example #2

Open mikemclin opened 9 years ago

ariellav commented 9 years ago

Hi there,

Awesome service you built out. I set the roles and abilities in my app.run and was able to get it working with my router. Now I am trying to use the AclService in other controllers, but the values don't carry over. How can I preserve the AclService to use across my app? This is an example of one of the controllers I am using:

(function () {

    var app = angular.module("mainApp");

    function routeUserController($rootScope, $scope, $http, $location, AclService) {

        $scope.can = AclService.can;
        console.log($scope.can('view_map'));
        console.log(AclService.hasRole('psAdmin'));
    }

    app.controller("RouteUserController", routeUserController);
}());
mikemclin commented 9 years ago

Theoretically, the code you are showing should work. It seems like you might have an issue elsewhere in your app. What values does the code you posted log out into the console? What values were you expecting?

Can you also provide the run code block, so I can inspect it?

ariellav commented 9 years ago

Hey,

Thanks for your reply and this awesome angular-acl module. I was running into something issues that ngRoute was giving me and migrated to ui-router instead. Now, everything is working much more smoothly, and the AclService is preserved across the app!

Thank you,

brunoneve commented 8 years ago

I use so , with ngRoute

app.run(['$rootScope', 'AclService',
    function($rootScope, AclService) {

        AclService.resume();
        $rootScope.acl = AclService;
   }
]);

throughout my app, template, I can use the acl calling dependent functions.

so

<li ng-show="acl.can('client.add')">
      <a ng-href="#/clients/new"><i class="fa fa-user-plus"></i> Adicionar</a>
</li>

or acl.hasRole('admin') , etc..

sw-tt-mayankpatel commented 7 years ago

It is working fine for ui-router also. Thanks @mikemclin @brunoneve

ariellav commented 7 years ago

Hi,

I'm actually not the creator of the issue so I don't have permissions to close it.

My apologies, I should have opened another Issue during that time and it seemed to have tangent off quite a bit.

Best,

On Wed, Jun 7, 2017 at 11:21 AM, Surendra Kumar B notifications@github.com wrote:

Hey @ariellav https://github.com/ariellav

Could you please close this issue if it works well for you?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mikemclin/angular-acl/issues/2#issuecomment-306881962, or mute the thread https://github.com/notifications/unsubscribe-auth/AH0WeV9xUVMBfc7eQq2ijW7vyCoT3io-ks5sBuoWgaJpZM4C0OTl .

--