最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

AngularJS監(jiān)聽(tīng)路由變化的方法

 更新時(shí)間:2017年03月07日 11:09:06   作者:淺岸  
本篇文章主要介紹了AngularJS監(jiān)聽(tīng)路由變化的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

使用AngularJS時(shí),當(dāng)路由發(fā)生改變時(shí),我們需要做某些處理,此時(shí)可以監(jiān)聽(tīng)路由事件,常用的是$routeStartChange, $routeChangeSuccess。完整例子如下:

<!DOCTYPE html>
<html>
<head>
 <meta charset="utf-8">
 <meta http-equiv="X-UA-Compatible" content="IE=edge">
 <title>AngularJS監(jiān)聽(tīng)路由變化</title>
</head>
<body ng-app="ngRouteExample">
  <div id="navigation"> 
   <a href="#/home" rel="external nofollow" >Home</a>
   <a href="#/about" rel="external nofollow" >About</a>
  </div>
   
  <div ng-view></div>

  <script type="text/ng-template" id="home.html">
   <h1> Home </h1>
   <table>
    <tbody>
     <tr ng-repeat="x in records" style="background:#abcdef;">
      <td>{{x.Name}}</td>
      <td>{{x.Country}}</td> 
     </tr>     
    </tbody>
   </table>
  </script>

  <script type="text/ng-template" id="about.html">
   <h1> About </h1>
   <p>在輸入框中嘗試輸入:</p>
   <p>姓名:<input type="text" ng-model="name"></p>
   <p>你輸入的為: {{name}}</p>
  </script>

  <script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
  <script src="http://apps.bdimg.com/libs/angular-route/1.3.13/angular-route.js"></script>
  <script type="text/javascript">
  angular.module('ngRouteExample', ['ngRoute'])
  .config(function ($routeProvider) {
    $routeProvider.
    when('/home', {
      templateUrl: 'home.html',
      controller: 'HomeController'
    }).
    when('/about', {
      templateUrl: 'about.html',
      controller: 'AboutController'
    }).
    otherwise({
      redirectTo: '/home'
    });
  })
  .run(['$rootScope', '$location', function($rootScope, $location) {
    /* 監(jiān)聽(tīng)路由的狀態(tài)變化 */
    $rootScope.$on('$routeChangeStart', function(evt, next, current){
     console.log('route begin change');
    }); 
    $rootScope.$on('$routeChangeSuccess', function(evt, current, previous) {
     console.log('route have already changed :'+$location.path());
    }); 
  }])
  .controller('HomeController', function ($scope) { 
    $scope.records = [{
     "Name" : "Alfreds Futterkiste",
     "Country" : "Germany"
    },{
     "Name" : "Berglunds snabbköp",
     "Country" : "Sweden"
    },{
     "Name" : "Centro comercial Moctezuma",
     "Country" : "Mexico"
    },{
     "Name" : "Ernst Handel",
     "Country" : "Austria"
    }]
  })    
  .controller('AboutController', function ($scope) { 
   $scope.name = '呵呵';
  });
</script>  
</body>
</html>

上述的例子是AngularJS 1的,對(duì)于Angular2是否也可以用,還沒(méi)嘗試過(guò),有機(jī)會(huì)驗(yàn)證了再記錄下咯~~

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Angular 多級(jí)路由實(shí)現(xiàn)登錄頁(yè)面跳轉(zhuǎn)(小白教程)

    Angular 多級(jí)路由實(shí)現(xiàn)登錄頁(yè)面跳轉(zhuǎn)(小白教程)

    這篇文章主要介紹了Angular 多級(jí)路由實(shí)現(xiàn)登錄頁(yè)面跳轉(zhuǎn)(小白教程),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-11-11
  • Angular 4 指令快速入門教程

    Angular 4 指令快速入門教程

    本篇文章主要介紹了Angular 4 指令快速入門教程,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-06-06
  • 詳解Angular4中路由Router類的跳轉(zhuǎn)navigate

    詳解Angular4中路由Router類的跳轉(zhuǎn)navigate

    這篇文章主要介紹了詳解Angular4中路由Router類的跳轉(zhuǎn)navigate,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-06-06
  • AngularJs 延時(shí)器、計(jì)時(shí)器實(shí)例代碼

    AngularJs 延時(shí)器、計(jì)時(shí)器實(shí)例代碼

    這篇文章主要介紹了AngularJs 延時(shí)器、計(jì)時(shí)器實(shí)例代碼,需要的朋友可以參考下
    2017-09-09
  • 詳解Angular CLI + Electron 開(kāi)發(fā)環(huán)境搭建

    詳解Angular CLI + Electron 開(kāi)發(fā)環(huán)境搭建

    本篇文章主要介紹了Angular CLI + Electron 開(kāi)發(fā)環(huán)境搭建,具有一定的參考價(jià)值,有興趣的可以了解一下
    2017-07-07
  • 最新評(píng)論

    婺源县| 元氏县| 那曲县| 察雅县| 桓台县| 寻乌县| 馆陶县| 宜良县| 汶上县| 成都市| 卢龙县| 绥宁县| 东丰县| 双桥区| 辉南县| 定陶县| 梁平县| 曲周县| 西畴县| 繁昌县| 汕尾市| 永定县| 海阳市| 资兴市| 神农架林区| 乾安县| 闸北区| 禄劝| 齐河县| 武清区| 海口市| 德清县| 竹北市| 延吉市| 客服| 武城县| 海南省| 额济纳旗| 米林县| 柳河县| 平和县|