I am writing a simple paging widget in Angular2Dart. The component has a route
method that should get the current route, update parameters, and navigate. I'm not sure I am doing this correctly, but in this current implementation, I am using router.currentInstruction
. The problem is router.currentInstruction
is null.
Here is the component (simplified for this question):
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]);
}
}