Angular4-从组件而不是模板更改状态 [英] Angular4 - Change state from component not template
本文介绍了Angular4-从组件而不是模板更改状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在AngularJS中,我使用ui-router在应用内部进行重定向(更改状态).
In AngularJS I used ui-router for redirecting inside of my app(changing state).
它有2种可能的重定向选项
It has 2 possible options to redirect
- 在模板
ui-sref='stateName'
中
- 在控制器
$state.go()
中
- In template
ui-sref='stateName'
- In controller
$state.go()
我刚开始使用Angular(4),我发现了唯一的方法来更改模板中的路线,例如:
I just start play with Angular (4) and I found only way how to change route from template with something like:
- 模板
routerLink="routePath"
UI路由器中是否有某种方法可以更改组件的路由?
Is there some way as there was in ui-router to change route from component?
推荐答案
constructor(private router:Router) {}
changeRoute() {
this.router.navigate(...)
// this.router.navigateByUrl(...)
}
另请参见 https://angular.io/docs/ts/latest/api/router/index/Router-class.html
这篇关于Angular4-从组件而不是模板更改状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文