angular6 - 角度 6 中的“路由器”类型上不存在属性“getCurrentNavigation”
问题描述
检索状态值:
import { Router,NavigationExtras } from '@angular/router';
constructor(private router: Router)
{
const navigation = this.router.getCurrentNavigation();
const state = navigation.extras.state as {example: string};
this.example = state.example;
}
路线导航
const navigationExtras: NavigationExtras = {state: {example: 'This is an example'}};
this.router.navigate(['/trace/geospatial'], navigationExtras);
我收到以下错误:
“Router”类型中不存在“getCurrentNavigation”属性,并且对象文字只能指定已知属性,“NavigationExtras”类型中不存在“状态”
解决方案
您需要Angular 7.2及更高版本才能使用该router.getCurrentNavigation()
方法。
推荐阅读
- android - LiveData 没有观察具有共享视图模型的子视图页面片段
- flutter - 实现 setstat 和绑定变量
- php - 使用 PHP 创建动态选择
- gnuplot - 如何将数据标签添加到 Gnuplot 直方图(平滑频率)?
- vuejs3 - Vue 3x Vue CLI 4.5x - 在本地运行良好,但 prod 中的 dist/ 文件夹出现问题
- php - 如何检查 json 值不等于 laravel 中的参数?
- mysql - 在 MySQL 中将多个表连接到一个没有 CTE 或 Row_Number 的表
- c# - 如何检查数据库中是否已存在值
- python - 多处理后连接结果数据帧
- events - 如何从外部触发 datalabels-plugin (active) - ChartJS