2015-10-27 110 views
0

JS爲創建兩個佈局和內容頁:加載UI路由器狀態,當網站首次加載

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

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

我的問題是,只有當我點擊與SREF =「網站的鏈接。電影「它出現,而不是在頁面加載,我如何使movies.html和其佈局加載站點先運行。 也當我在地址欄中輸入/網站/電影movies.html不加載。

+0

1 thing..MVC不提供訪問視圖folder..in短你不能訪問視圖文件夾中的文件直接通過URL –

回答

0

我找到了解決辦法是嵌套狀態網址:

.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' 
    }) 
相關問題