I have been trying something similar using an array to set up the routes 
for my page. The only way I could get it to work was by using the $get 
function directly to do my bidding:

.provider('pages', function () {

   this.$get = function () {

     return [

       { name: 'home', text: 'Home', enabled: true, active: false },

       { name: 'gallery', text: 'Gallery', enabled: true, active: false },

       { name: 'services', text: 'Services', enabled: false, active: false 
},

       { name: 'pricing', text: 'Pricing', enabled: false, active: false },

       { name: 'test', text: 'Test', enabled: false, active: false }

    ];

}

});

And then calling it in my config section like:

   pages.$get()

Which is obviously not the right way to do that... but it seems to work.

On Tuesday, September 10, 2013 11:29:14 AM UTC-7, Olger Warnier wrote:

> Hi List, 
>
> I found some topics on the possibility to use a function for your 
> templateUrl inside the $routeProvider (in the config of a module)
> With the comments on these topics (this functionality was added at that 
> time), I ended up with using AngularJS 1.2.0-rc.2 and:
>
> var mainModule = angular.module('mainModule', ['ngCookies', 'ngRoute', 
> 'ui', '$strap.directives', 'LoginModule']).
>     config(function ($routeProvider) {
>
>
>       var isAdmin = function(projectId) {
>           //angular.$injector = ['LoginProvider'];
>
>           //console.log("in isAdmin " + LoginProvider.loginName);
>           return (projectId == '9f0a1a6d-c784-4561-be96-fa7c9ee6aa3a')
>       };
>
>       $routeProvider.
>           when('/projects/:projectId', {
>               controller  : ProjectCtrl,
>               templateUrl: function (args) {
>                 if (isAdmin(args.projectId)) {
>                     return 'js/project/project_admin.html';
>                 } else {
>                     return 'js/project/project.html';
>                 }
>               }
> At the spot where the projectId is matched to a UUID, I'd like to use my 
> LoginProvider and check if the given projectId (via the args of the 
> templateUrl function) is allowed to edit this project. (and serve another 
> template)
>
> I've tried all kind of options and found that a provider 
> (mainModule.provider('LoginProvider' ……. ) is required when you want to 
> inject into the config and make use of that in your $routeProvider. Somehow 
> This doesn't seem to work. (found some excellent articles on writing 
> services, factories and providers. 
>
> The LoginProvider I've tried to use looks like:
>
> loginModule.provider('LoginProvider', function() {
>
>     this.$get = function() {
>         return {
>             loginName : 'olger',
>             isAdmin : function() {
>                 return true;
>             }
>         };
>     };
> });
>
> In what way should I inject this provider in order to make use of it for 
> checking admin rights ?
> (or is something wrong with the way the provider is written..)
>
> Kind regards, 
>
> Olger
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to