在网站首次加载时加载ui-router状态

时间:2021-06-29 19:38:34

js for creating two layout and a content page is:

用于创建两个布局和内容页面的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 is:

<!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>
​

That I removed script references. Site.html is:

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

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

and movies.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>​

My problem is only when I click the link with sref="site.movies" it appears and not on page load, How do I make movies.html and its layout load site runs first. also when I type /site/movies in the address bar movies.html does not load.

我的问题是,当我点击sref =“site.movi​​es”链接时,它出现而不是页面加载,我如何使movies.html及其布局加载网站首先运行。当我在地址栏中输入/ site / movies时,movies.html也没有加载。

1 个解决方案

#1


0  

I found the solution is in nested state url:

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

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

should be:

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

#1


0  

I found the solution is in nested state url:

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

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

should be:

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