我正在 Angular2Dart 中编写一个简单的分页小部件。该组件有一个route
方法应该获取当前路由、更新参数和导航。我不确定我这样做是否正确,但在当前的实现中,我使用的是router.currentInstruction
. 问题router.currentInstruction
是空的。
这是组件(针对此问题进行了简化):
import 'package:angular2/angular2.dart';
import 'package:angular2/router.dart';
import 'package:angular_components/angular_components.dart';
@Component(
selector: 'paging-component',
templateUrl: 'paging_component.html',
styleUrls: const [
'paging_component.css'
],
directives: const [
CORE_DIRECTIVES,
FORM_DIRECTIVES,
materialDirectives,
],
)
class PagingComponent {
final RouteParams routeParams;
final Router _router;
PagingComponent(this.routeParams, this._router);
void _route([Map<String, String> updatedParams]) {
var existingParams = new Map.from(routeParams.params);
if (updatedParams != null) {
existingParams.addAll(updatedParams);
}
var currentRoute = _router.currentInstruction.component.routeName;
_router.navigate([currentRoute, existingParams]);
}
}