繁体   English   中英

网站首次加载时加载ui路由器状态

[英]Load a ui-router state when website first loads

用于创建两个布局和一个内容页面的js是:

 $urlRouterProvider.otherwise("/Site/Movies");


    $stateProvider
      .state('admin', {
          url: "/Admin",
          templateUrl: "/Views/Admin.html"
      })
      .state('site', {
          url: "/Site",
          templateUrl: "/Views/Site.html"
      })          
      .state('site.movies', {
          url: "/Site/Movies",
          templateUrl: "/Views/Site/movies.html",
          controller: 'moviesController'
      })

Index.html是:

 <!DOCTYPE html> <html ng-app="moviesApp"> <head></head> <body ng-cloak> <!--<div class="container-fluid"> <ng-view></ng-view> </div>--> <div ui-view></div> <a ui-sref="site.movies">State 1</a> </body> </html>​ 

我删除了脚本引用。 Site.html是:

  <header id="siteHeader">HEADER</header> <div ui-view></div> <footer id="siteFooter">FOOTER</footer>​ 

和movie.html

 <div> <h1>List Movies</h1> <button ng-click="getMovies()">Get Movies</button> <span>{{error}}</span> <table class="table table-bordered table-striped"> <thead> <tr> <th></th> <th>Title</th> <th>Director</th> </tr> </thead> <tbody> <tr ng-repeat="movie in movies"> <td> <a href="/movies/edit/{{movie.Id}}" class="btn btn-default btn-xs">edit</a> <a href="/movies/delete/{{movie.Id}}" class="btn btn-danger btn-xs">delete</a> </td> <td>{{movie.Title}}</td> <td>{{movie.Director}}</td> </tr> </tbody> </table> <p> <a href="/movies/add" class="btn btn-primary">Add New Movie</a> </p> </div>​ 

我的问题是,仅当我单击带有sref =“ site.movi​​es”的链接时才显示该链接,而不是页面加载时,如何制作Movies.html及其布局加载站点首先运行。 当我在地址栏中键入/ site / movies时,movies.html也不会加载。

我发现解决方案处于嵌套状态url:

.state('site.movies', {
      url: "/Site/Movies",
      templateUrl: "/Views/Site/movies.html",
      controller: 'moviesController'
  })

应该:

.state('site.movies', {
      url: "/Movies",
      templateUrl: "/Views/Site/movies.html",
      controller: 'moviesController'
  })

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM