角ngRoute:力纳克 - 浏览内容,以便事后导航事后、纳克、内容、ngRoute

2023-09-13 05:04:00 作者:久居我心-

当使用ngRoute,我想有角配置,以便纳克视图的当前内容被留下作为当前路线的内容,并允许用户导航离开到不同的路线,之后呈现各自的模板:

While using ngRoute, I want to have Angular configured so that the current contents of ng-view are left as the contents for the current route, and allow the user to navigate away to different routes, rendering their respective templates afterwards:

HTML

<ul class="menu">
  <li><a href="#/view1">view1</a></li>
  <li><a href="#/view2">view2</a></li>
</ul>

<div ng-view>
  <ul>
    <li>Some</li>
    <li>Soon obliterated</li>
    <li>Content</li>
  </ul>
</div>

的JavaScript

angular.module('myApp', ['ngRoute'])
.config(function($routeProvider) {
  $routeProvider
  .when('/view1', {
    templateUrl: 'view1.html',
    controller: 'View1Ctrl'
  })
  .when('/view2', {
    templateUrl: 'view2.html',
    controller: 'View2Ctrl'
  })
  .otherwise({
    redirectTo: '/view1'
  })
})
.controller('View1Ctrl', function() {

})
.controller('View2Ctrl', function() {

});

当用户第一次看到的页面,我希望他看到以下内容:的

When the user first sees the page, I want him to see the following:

注意:角需要在这点上被自举,以指示在这方面的作用的

的注2:此内容应该是在页面的实际的HTML,而不是在模板或脚本标记的

然后,当点击视图2链接:的

Then, when the 'view2' link is clicked:

然后,当点击视图1链接:的

And then, when the 'view1' link is clicked: