html - Angular CLI / TypeScript方法中的RouterLink?
问题描述
我必须将我的 URL 链接 (actionsConfig) 导入我的组件。
在 HTML 中我曾经使用“路由器链接”,它在 TypeScript 中是如何工作的?
动作配置.ts:
export const ACTIONS = [
{
label: 'Delete',
actionType: 'DELETE',
},
{
label: 'Edit',
actionType: 'GO_TO',
getUrl: row => '/detail/' + row.id,
},
];
组件.ts:
actionFunc(action, user: User) {
if (action.actionType === 'DELETE') {
if (confirm('Are you sure you want to delete this item?') === true) {
/*delete ok*/
}
}
if (action === 'GO_TO') {
const url = action.getUrl(user);
/* GO TO URL (routerlink?) */
}
}
解决方案
更新 这个对我有用。
constructor(private router: Router) {
}
/.../
if (action.actionType === 'GO_TO') {
console.log('test');
const url = action.getUrl(user);
this.router.navigateByUrl(url).then();
}
推荐阅读
- security - 我桌面上的一个高编号端口刚刚被扫描,我应该担心吗?
- ansible - Ansible-Ping 一个 IP 地址和如果不可达设置变量在 ansible 中不可用为真或可用为假
- javascript - 1 个表中的 2 个 foreach 无法正常工作
- vb.net - 在后台轻松运行功能
- spring-boot - 在微服务项目中使用 Spring Boot 云配置服务器的配置服务器配置无效
- javascript - 将 JavaScript 代码附加到 div 后如何运行它们
- reactjs - React toastify toast 每次调用都会出现 4 次
- powershell - 从段落powershell中过滤单词
- javascript - Javascript函数无法更新变量
- regex - 使用正则表达式匹配mongodb集合中文档中的项目数组的字符串