如何在ES5编写的Angular2路由代码中获取URL参数?

时间:2016-05-08 18:40:10

标签: angular angular2-routing

以下是TypeScript代码的示例:

<fieldset class="standard">
  <legend>Desktop</legend>
  <ul>
    <li ng-repeat="item in vm.data.desktop">
      <md-checkbox aria-label="title" ng-onclick="doSomething">
        {{item.label}}
      </md-checkbox>
    </li>
  </ul>
</fieldset>
<fieldset class="standard">
  <legend>Mobile</legend>
  <ul>
    <li ng-repeat="item in vm.data.mobile">
      <md-checkbox aria-label="title" ng-true-value="false">
        {{item.label}}
      </md-checkbox>
    </li>
  </ul>
</fieldset>

<fieldset class="standard">
  <legend>Metrics</legend>
  <ul>
    <li ng-repeat="item in vm.data.metrics">
      <md-checkbox aria-label="title">
        {{item.label}}
      </md-checkbox>
    </li>
  </ul>
</fieldset>

如何在ES5中编写它,即如何在ES5中获取查询参数?

1 个答案:

答案 0 :(得分:2)

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

确保提供ROUTER_PROVIDERS,如

(function (app) { 
  document.addEventListener('DOMContentLoaded', function () {   
    ng.platform.browser.bootstrap(app.AppComponent, 
        [ng.router.ROUTER_PROVIDERS]); 
  }); 
})(window.app || (window.app = {}));