1

I am angular newbie.I would like to achieve following code...

 $routeProvider.when('/view', {templateUrl: 'ViewSwitcher?pageId='+$rootSope.pageId+'&userId='+$rootSope..userId+'&token='+$rootScope.token, controller: ''});

ViewSwitcher is a servelet which responses me a HTML page as per pageId,userId(saved in $rootScope) ......but $rootScope is not available....Thanks in advance!

Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299
AKRICK
  • 55
  • 1
  • 7

1 Answers1

0

You could do one thing here instead of store this variables inside the $rootScope use provider that could be easily accessible inside the config phase. Create one myData provider that would share a data between different components of your app.

Code

//before using `myDataProvider` make sure it has been injected as dependency.
$routeProvider.when('/view', {
    templateUrl: 'ViewSwitcher?pageId='+myDataProvider.pageId+'&userId='+ myDataProvider.userId+'&token='+ myDataProvider.token,
    controller: 'myCtrl' //<--here it should be some controller
});
Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299
  • Thanks Pankaj for your valuable reply......I have defined provider like this : myApp.provider('configurableProvider', function () { var name = 'xyz'; this.setName = function (newName) { name = newName; }; this.$get = function () { return name; }; }); and using like myApp.config(['$routeProvider','configurableProvider', function ($routeProvider,configurableProvider) { ...........but getting error unknown provider(i think wrong injection) ...... – AKRICK Aug 25 '15 at 14:03
  • @AKRICK your provider name should be `configurable` only..while using it in configuration phase you need to post fix it with `Provider` like it will used as `configurableProvider` & other than config phase you could use that by `configurable` – Pankaj Parkar Aug 25 '15 at 14:25
  • at Pankaj: done all fixes .running but still getting undefined in url......pharmApp.config(['$routeProvider','configurableProvider', function ($routeProvider,configurable) {.................... – AKRICK Aug 26 '15 at 06:25
  • could you update you question with what you have tried till? – Pankaj Parkar Aug 26 '15 at 06:51
  • 1
    I achieved using ...App.config(['$routeProvider', function ($routeProvider) { $routeProvider.when('/view1', {templateUrl: function(configurable){ debugger; var obj=angular.element('*[ng-app]').injector().get("configurable"); return 'ViewSwitcher?pageId='+obj.pageId+'&userId='+obj.userId+'&token='+obj.token; }, controller: '' }); ................thanks ! – AKRICK Aug 26 '15 at 12:25