1

Here is an example of TypeScript code:

class LoginComponent{
   token: string;
   constructor(params: RouteParams) {
      this.token = params.get('token');
   }
}

How to write it in ES5 i.e., how to get query parameters in ES5?

1 Answer 1

2
var LoginComponent = ng.core.Component({
  ...
}).
Class({
  constructor: [ng.router.RouteParams, function(params) {
    this.token = params.get('token');
  }]
});

Ensure ROUTER_PROVIDERS are provided like

(function (app) { 
  document.addEventListener('DOMContentLoaded', function () {   
    ng.platform.browser.bootstrap(app.AppComponent, 
        [ng.router.ROUTER_PROVIDERS]); 
  }); 
})(window.app || (window.app = {}));
Sign up to request clarification or add additional context in comments.

5 Comments

RouteParams is undefined
Did you import RouteParams? Did you provide ROUTER_PROVIDERS?
import? In ES5 we don't import. We use ng.core instead.
We also need to provide ViewProvider right?? becz its a service
Providing with bootstrap like (function (app) { document.addEventListener('DOMContentLoaded', function () { ng.platform.browser.bootstrap(app.AppComponent, [ng.router.ROUTER_PROVIDERS]); }); })(window.app || (window.app = {})); should do. ROUTER_DIRECTIVES need to be added to directives at every component where they are used, ROUTER_PROVIDERS only once in bootstrap() or providers of the root component.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.