Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 无法在用户界面路由器中加载父路由_Angularjs_Angular Ui Router - Fatal编程技术网

Angularjs 无法在用户界面路由器中加载父路由

Angularjs 无法在用户界面路由器中加载父路由,angularjs,angular-ui-router,Angularjs,Angular Ui Router,在我的应用程序中,我有一些主要模块,每个模块都有侧边栏。 如果我单击侧栏项目,它将路由到侧栏链接页面,但如果我再次单击标题,则无法查看父路由页面。 我已将我的问题列在此列表中。 复制步骤: 默认情况下,route1处于选中状态,仪表板在视图中可用。点击Item1 现在单击route1:无法查看仪表板视图 var myapp=angular.module('myapp',[“ui.router”]) myapp.config(函数($stateProvider,$urlRouterProvide

在我的应用程序中,我有一些主要模块,每个模块都有侧边栏。
如果我单击侧栏项目,它将路由到侧栏链接页面,但如果我再次单击标题,则无法查看父路由页面。
我已将我的问题列在此列表中。
复制步骤:

  • 默认情况下,route1处于选中状态,仪表板在视图中可用。点击Item1
  • 现在单击route1:无法查看仪表板视图
  • 
    var myapp=angular.module('myapp',[“ui.router”])
    myapp.config(函数($stateProvider,$urlRouterProvider){
    //对于任何不匹配的url,请发送到/route1
    $urlRouterProvider。否则(“/route1”)
    $stateProvider
    .state('route1'{
    url:“/route1”,
    templateUrl:“route1.html”,
    控制器:函数($scope,$state){
    $scope.items=[“item1”,“item2”];
    $state.go('route1.dashboard');
    }
    })
    .state('route1.dashboard'{
    url:“/dashboard”,
    templateUrl:“dashboard.html”
    })
    .state('route1.item1'{
    url:“/item1”,
    templateUrl:“item1.html”
    })
    .state('route1.item2'{
    url:“/item2”,
    templateUrl:“item2.html”
    })
    .state('route2'{
    url:“/route2”,
    templateUrl:“route1.html”,
    控制器:函数($scope,$state){
    $scope.items=[“item3”,“item4”];
    $state.go('route2.dashboard');
    }
    })
    .state('route2.dashboard'{
    url:“/dashboard”,
    templateUrl:“dashboard.html”
    })
    .state('route2.item3'{
    url:“/item3”,
    templateUrl:“item3.html”
    })
    .state('route2.item4'{
    url:“/item4”,
    templateUrl:“item4.html”
    })
    })
    
    路由器1控制器中的代码仅在实例化时运行。因此,在您从item1中重新访问它之后,它不需要重新加载,$state.go()也不会启动

    我已经用另一种可能的方法来对付你:

    您应该将仪表板内容放在route1模板中,而不是试图通过$state.go()转发给它

    因此,您的route1.html来自

    <div ui-view></div>
    
    
    

    
    仪表板
    
    现在,您不需要仪表板部分,而且每次都会加载。每当这些状态激活时,item1/item2部分将替换ui视图中的内容

    在更新后的Plunker中,请注意Route1是如何按照您的意愿工作的,而Route2仍然不工作(因为它仍然使用以前的$state.go()方法)

    <div ui-view></div>
    
      <div ui-view>
        <h1>Dashboard</h1>
      </div>