I have to import my URL link (actionsConfig) to my component.
In HTML I used to use "router link", how does it work in TypeScript?
actionsConfig.ts :
export const ACTIONS = [
{
label: 'Delete',
actionType: 'DELETE',
},
{
label: 'Edit',
actionType: 'GO_TO',
getUrl: row => '/detail/' + row.id,
},
];
component.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?) */
}
}
答案 0 :(得分:0)
更新 这对我有用。
constructor(private router: Router) {
}
/.../
if (action.actionType === 'GO_TO') {
console.log('test');
const url = action.getUrl(user);
this.router.navigateByUrl(url).then();
}