【问题标题】:AngularJS 2 Dart get RouterLink ParameterAngularJS 2 Dart 获取 RouterLink 参数
【发布时间】:2017-01-20 22:33:15
【问题描述】:

我想在 Angular 中创建一个详细信息页面,并希望通过 RouterLink 传递一个条目 ID。有没有办法获取url中的参数?

网址如下:http://localhost:8080/details?date=13-09-2016

【问题讨论】:

    标签: angularjs angular dart angular2-routing


    【解决方案1】:

    也可以使用RouteParams获取参数。您可以将其注入到您的组件中:

    @Component(...)
    class MyDetailsComponent {
      final RouteParams _routeParams;
      MyDetailsComponent(this._routeParams){
        var date = _routeParams.get('date');
      }
    }
    

    您可以找到更多详细信息here

    【讨论】:

      【解决方案2】:

      实现OnActivate

        @override
        routerOnActivate(ComponentInstruction nextInstruction,
            ComponentInstruction prevInstruction) {
          String routeParamValue = nextInstruction.params['paramName'];
          String queryParamValue = nextInstruction.urlParams['paramName'];
        }
      

      【讨论】:

      • 我必须把这个放在哪里?我必须把它放在组件的类部分吗?
      • 到路由器添加的组件。对于查询参数,您需要将params 更改为queryParamsparam 用于路由参数(path: '/some/:paramName/other'
      • 它不起作用。它甚至没有被调用我已经将它更改为 queryParams 但它甚至没有被调用。我的路由看起来像这样:@RouteConfig(const [ const Route(path: '/view', name: 'Home', component: SimpleKVComponent, useAsDefault: true), const Route(path: '/settings', name: 'Settings', component: SettingsComponent), const Route(path: '/details', name: 'Details', component: DetailsComponent) ])
      • 它被这行调用:<td><a [routerLink]="['/Details', { date: history['link'] }]"><i class="glyphicon glyphicon-eye-open"></i></a></td>
      • 你添加class DetailsComponent implements OnActivate {了吗?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-09-16
      • 1970-01-01
      • 2014-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多