[英]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.movies”的鏈接時才顯示該鏈接,而不是頁面加載時,如何制作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.