У меня проблемы с тем, что может показаться тривиальным.
Я создал маршрут, который можно просмотреть на /cans/1
, и когда я туда доберусь, я могу просматривать контент.
Что касается меня, я не могу понять, как получить параметр 1 из URL в представлении.
import 'package:angular/angular.dart';
@Component(
selector: 'canId-summary',
template: '''
<div>
<h1>canId Summary</h1>
{{canId}}
</div>
''',
directives: [coreDirectives],
)
class CanComponent {
void canId() {
// how do I get the $id out of the url for here?
}
}
Маршрут работает для этого контента
import 'package:angular_router/angular_router.dart';
const idParam = 'id';
class RoutePaths {
static final dashboard = RoutePath(path: 'dashboard');
static final cans = RoutePath(path: 'cans');
static final can = RoutePath(path: '${cans.path}/:$idParam');
}
int getId(Map<String, String> parameters) {
final id = parameters[idParam];
return id == null ? null : int.tryParse(id);
}
import 'package:angular_router/angular_router.dart';
import 'route_paths.dart';
import 'dashboard_component.template.dart' as dashboard_template;
import 'cans_component.template.dart' as cans_template;
import 'can_component.template.dart' as can_template;
export 'route_paths.dart';
class Routes {
static final dashboard = RouteDefinition(
routePath: RoutePaths.dashboard,
component: dashboard_template.DashboardComponentNgFactory,
);
static final cans = RouteDefinition(
routePath: RoutePaths.assessments,
component: cans_template.CansComponentNgFactory,
);
static final can = RouteDefinition(
routePath: RoutePaths.can,
component: can_template.CanComponentNgFactory,
);
static final all = <RouteDefinition>[
dashboard,
cans,
can,
RouteDefinition.redirect(
path: '',
redirectTo: RoutePaths.dashboard.toUrl(),
),
];
}