Ui-router -使用相同的路由加载模板和子视图

ui-router - loading template and childview at the using the same route

本文关键字:加载 视图 路由 Ui-router      更新时间:2023-09-26

我是ui-router的新手,我希望有人能帮助我从一个路由加载2个视图。我正在查看示例plunk,我试图让它在加载子视图的同时加载路由,但我无法让这个plunk工作。我认为,通过创建一个抽象路由,然后调用状态。在子路线,它会工作,但我错过了一些东西。

欢迎指教。

        controller: function($scope){
            $state.go('route1.list');
            $scope.items = ["A", "List", "Of", "Items"];
          }

你得到的错误正好指出了这个问题,你已经定义了route1是抽象的,这很好,但是你不能去一个抽象状态,抽象状态只有在你导航到抽象状态的子状态时才运行,所以你必须去一个子状态,所以把ui-sref="route1"改为ui-sref="rout1.list":

<li><a ui-sref="route1.list">Route 1</a></li>

并将$state注入route1.list的控制器:

.state('route1.list', {
              url: "/list",
              templateUrl: "route1.list.html", //child view
              controller: function($scope,$state){
                $state.go('route1.list');
                $scope.items = ["A", "List", "Of", "Items"];
              }
          })

参见working plunk