{"action":"created","issue":{"url":"https://api.github.com/repos/Narzerus/angular-permission/issues/150","repository_url":"https://api.github.com/repos/Narzerus/angular-permission","labels_url":"https://api.github.com/repos/Narzerus/angular-permission/issues/150/labels{/name}","comments_url":"https://api.github.com/repos/Narzerus/angular-permission/issues/150/comments","events_url":"https://api.github.com/repos/Narzerus/angular-permission/issues/150/events","html_url":"https://github.com/Narzerus/angular-permission/issues/150","id":133261211,"number":150,"title":"permission directive could watch for changes?","user":{"login":"atais","id":1538192,"avatar_url":"https://avatars.githubusercontent.com/u/1538192?v=3","gravatar_id":"","url":"https://api.github.com/users/atais","html_url":"https://github.com/atais","followers_url":"https://api.github.com/users/atais/followers","following_url":"https://api.github.com/users/atais/following{/other_user}","gists_url":"https://api.github.com/users/atais/gists{/gist_id}","starred_url":"https://api.github.com/users/atais/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/atais/subscriptions","organizations_url":"https://api.github.com/users/atais/orgs","repos_url":"https://api.github.com/users/atais/repos","events_url":"https://api.github.com/users/atais/events{/privacy}","received_events_url":"https://api.github.com/users/atais/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2016-02-12T14:57:04Z","updated_at":"2016-02-16T10:51:46Z","closed_at":"2016-02-13T16:30:50Z","body":"Hi! \r\n(very big thank you for this project, I missed this functionalities a lot!)\r\n\r\nI am currently using 2.0.6 and I really like the idea of letting the permissions to control more than just the routing. For some time now I had been using my custom solution for handling showing/hiding some HTML elements. I gave your solution a shot.\r\n\r\nWhat I believe it lacks is the possibility to re-run the directive function when some permissions (or user) change. In my case f.e. I need to hide a menu-bar when someone logs out from the app. But to show it, when he logs in. It happens without refreshing of the application.\r\n\r\nThe solution I am currently using looks like this:\r\n\r\n```javascript\r\nangular\r\n        .module('app.permissions')\r\n        .directive('accessLevel', AccessLevel);\r\n\r\n    /* @ngInject */\r\n    function AccessLevel(Roles, $rootScope) {\r\n        return {\r\n            restrict: 'A',\r\n            link: function (scope, element, attrs) {\r\n                function update() {\r\n                    Roles.isUserInRole(attrs.accessLevel).then(function () {\r\n                        element.removeClass('unauthorized');\r\n                    }, function () {\r\n                        element.addClass('unauthorized');\r\n                    });\r\n                }\r\n\r\n                update();\r\n                $rootScope.$on('user:change', update);\r\n            }\r\n        };\r\n    }\r\n```\r\n\r\nIt's obvious weakness is that I need to emit 'user:change' at some points in my application, but the whole thing works. Currently I do not have better idea to handle it, but I am willing to brainstorm and contribute to the project :).\r\n\r\nCheers!\r\n "},"comment":{"url":"https://api.github.com/repos/Narzerus/angular-permission/issues/comments/184624563","html_url":"https://github.com/Narzerus/angular-permission/issues/150#issuecomment-184624563","issue_url":"https://api.github.com/repos/Narzerus/angular-permission/issues/150","id":184624563,"user":{"login":"atais","id":1538192,"avatar_url":"https://avatars.githubusercontent.com/u/1538192?v=3","gravatar_id":"","url":"https://api.github.com/users/atais","html_url":"https://github.com/atais","followers_url":"https://api.github.com/users/atais/followers","following_url":"https://api.github.com/users/atais/following{/other_user}","gists_url":"https://api.github.com/users/atais/gists{/gist_id}","starred_url":"https://api.github.com/users/atais/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/atais/subscriptions","organizations_url":"https://api.github.com/users/atais/orgs","repos_url":"https://api.github.com/users/atais/repos","events_url":"https://api.github.com/users/atais/events{/privacy}","received_events_url":"https://api.github.com/users/atais/received_events","type":"User","site_admin":false},"created_at":"2016-02-16T10:51:46Z","updated_at":"2016-02-16T10:51:46Z","body":"@masterspambot I have created a simple plunker to show you my problem.\r\nhttp://plnkr.co/edit/RvjmaM?p=preview\r\n\r\nThe deal is, in ```script.js``` - set the ```var user``` to ```'user'``` or ```undefined```.\r\nThis is a simulation of what happens in my application.\r\n\r\nSometimes, during the app initialization the user is already logged in. I restore the session from the server, sometimes it is not possible. And then he logs in manually. \r\nThe problem is, when I update the user in application - I change his permissions **and this change is not seen by the directive**.\r\n\r\nWhat could be done?"}}