亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

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

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

<!DOCTYPE html>
<html>
<head>
 <meta charset="utf-8">
 <meta http-equiv="X-UA-Compatible" content="IE=edge">
 <title>AngularJS監(jiān)聽路由變化</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à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的,對于Angular2是否也可以用,還沒嘗試過,有機會驗證了再記錄下咯~~

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

相關(guān)文章

  • Angular4實現(xiàn)鼠標(biāo)懸停3d傾斜效果

    Angular4實現(xiàn)鼠標(biāo)懸停3d傾斜效果

    這篇文章主要介紹了Angular4實現(xiàn)鼠標(biāo)懸停3d傾斜效果,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2017-10-10
  • AngularJS 如何在控制臺進行錯誤調(diào)試

    AngularJS 如何在控制臺進行錯誤調(diào)試

    本文主要介紹AngularJS 如何在控制臺進行錯誤調(diào)試,還不錯,分享給大家,希望給大家做一個參考。
    2016-06-06
  • angular過濾器實現(xiàn)排序功能

    angular過濾器實現(xiàn)排序功能

    這篇文章主要為大家詳細(xì)介紹了angular過濾器實現(xiàn)排序功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-06-06
  • python爬取安居客二手房網(wǎng)站數(shù)據(jù)(實例講解)

    python爬取安居客二手房網(wǎng)站數(shù)據(jù)(實例講解)

    下面小編就為大家?guī)硪黄猵ython爬取安居客二手房網(wǎng)站數(shù)據(jù)(實例講解)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-10-10
  • 解決angularJS中input標(biāo)簽的ng-change事件無效問題

    解決angularJS中input標(biāo)簽的ng-change事件無效問題

    今天小編就為大家分享一篇解決angularJS中input標(biāo)簽的ng-change事件無效問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-09-09
  • angular使用md5,CryptoJS des加密的方法

    angular使用md5,CryptoJS des加密的方法

    這篇文章主要介紹了angular使用md5,CryptoJS des加密的方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-06-06
  • Angular模板表單校驗方法詳解

    Angular模板表單校驗方法詳解

    這篇文章主要為大家詳細(xì)介紹了Angular模板表單校驗方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-08-08
  • Angular 2父子組件之間共享服務(wù)通信的實現(xiàn)

    Angular 2父子組件之間共享服務(wù)通信的實現(xiàn)

    這篇文章主要給大家介紹了關(guān)于Angular 2父子組件之間共享服務(wù)通信的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起看看吧。
    2017-07-07
  • angularjs 處理多個異步請求方法匯總

    angularjs 處理多個異步請求方法匯總

    這篇文章主要介紹了angularjs 處理多個異步請求方法匯總,需要的朋友可以參考下
    2015-01-01
  • angularjs http與后臺交互的實現(xiàn)示例

    angularjs http與后臺交互的實現(xiàn)示例

    這篇文章主要介紹了angularjs http與后臺交互的實現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-12-12

最新評論