Angular2Dart Router.currentInstruction 未设置
Angular2Dart Router.currentInstruction not being set
我正在 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]);
}
}
您可以使用
获取当前指令
@override
void routerOnActivate(next, prev) {
print('Activating ${next.routeName} ${next.urlPath}');
}
可能还有其他方法。我无法确定您的示例中的 _router.currentInstruction
是否有效。这可能取决于从哪里调用 route(...)
。
另见 https://webdev.dartlang.org/angular/api/angular2.router/OnActivate-class
我正在 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]);
}
}
您可以使用
获取当前指令@override
void routerOnActivate(next, prev) {
print('Activating ${next.routeName} ${next.urlPath}');
}
可能还有其他方法。我无法确定您的示例中的 _router.currentInstruction
是否有效。这可能取决于从哪里调用 route(...)
。
另见 https://webdev.dartlang.org/angular/api/angular2.router/OnActivate-class