[英]Load a ui-router state when website first loads
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: 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>
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 和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>
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. 我的问题是,仅当我单击带有sref =“ site.movies”的链接时才显示该链接,而不是页面加载时,如何制作Movies.html及其布局加载站点首先运行。 also when I type /site/movies in the address bar movies.html does not load.
当我在地址栏中键入/ site / movies时,movies.html也不会加载。
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'
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.