IJR
IJR

Reputation: 1338

angularjs ui-router pass query string parameter to state's templateurl

I need to pass the query string to templateUrl as html is generated by Django view in this case.

I am trying to pass parameters(itemId) to templateUrl in angularjs ui-router like the following:

    .state('MyApp.itemEdit',{
        url: '/items/:itemId',
        views: {
            'editItems@':{
                templateUrl: '/core/edit-item-tmpl?itemId',
                controller: 'EditItemCtrl as editItems'
            }
        }
    })

This is not working. Wanted to know whether this can be done as I am not able to find anything related to this in docs.

Thanks

Upvotes: 1

Views: 1262

Answers (1)

New Dev
New Dev

Reputation: 49590

You can get the itemId parameter if you used a function for templateUrl:

.state('MyApp.itemEdit',{
        url: '/items/:itemId',
        views: {
            'editItems@':{
                templateUrl: function(params){
                   return '/core/edit-item-tmpl?' + params.itemId;
                },
                controller: 'EditItemCtrl as editItems'
            }
        }
    })

Upvotes: 4

Related Questions