Ui-Router:获取控制器中的视图名称

时间:2022-04-17 10:46:20

With the ui-router for angularJS you can use multiple views on the same page/state.

使用用于angularJS的ui-router,您可以在同一页面/状态上使用多个视图。

Each view contains a template, controller, etc. but it seems like unlike for states there is no way to assign a "resolve" function to a view.

每个视图都包含一个模板,控制器等,但似乎与状态不同,无法为视图分配“解析”功能。

Now i have several similar views which are using the same controller (which means the controller gets instanciated once per view). Obviously I need to pass some information to the controller, depending on which view he is currently managing. Preferably I would do this when the controllers get instanciated. I can not access this information inside the controller via $state though since it does not provide informations on the view assigned to the controller..

现在我有几个类似的视图使用相同的控制器(这意味着控制器每个视图获得一次实例化)。显然,我需要将一些信息传递给控制器​​,具体取决于他当前管理的视图。当控制器实现时,我最好这样做。我无法通过$ state在控制器内访问此信息,因为它不会在分配给控制器的视图上提供信息。

Since the view is establishing the link between template and controller (and manage its lifecycle via ui-view, i was hoping i could pass information to the controller using the view-object. Without a resolve function i do not see a way to do this though, so is there another way?

由于视图正在建立模板和控制器之间的链接(并通过ui-view管理其生命周期,我希望我可以使用视图对象将信息传递给控制器​​。没有解析功能,我看不到这样做的方法虽然,还有另一种方式吗?

1 个解决方案

#1


0  

You can use $state.$current to get the name of the current state.

您可以使用$ state。$ current来获取当前状态的名称。

#1


0  

You can use $state.$current to get the name of the current state.

您可以使用$ state。$ current来获取当前状态的名称。