茄子在线看片免费人成视频,午夜福利精品a在线观看,国产高清自产拍在线观看,久久综合久久狠狠综合

    <s id="ddbnn"></s>
  • <sub id="ddbnn"><ol id="ddbnn"></ol></sub>

  • <legend id="ddbnn"></legend><s id="ddbnn"></s>

    Angularjs中UI Router的使用方法
    來源:易賢網(wǎng) 閱讀:1003 次 日期:2016-06-30 16:41:31
    溫馨提示:易賢網(wǎng)小編為您整理了“Angularjs中UI Router的使用方法”,方便廣大網(wǎng)友查閱!

    學習使用angular中,ui-route是其中的一個難點,簡單使用沒什么問題,但涉及到多級嵌套,就感覺有茫然,查了很多資料,踩過很多坑,到目前為止也不能說對ui-route有全面了解;這里只是把填補的幾個坑記錄一下備忘:

    1.abstract的使用:

    $stateProvider

      .state('shop',{

        resolve:{

          "shoplist":function($http){

            return $http({

              url:"/bookApp/data/shoplist.php",

              method:"GET"

            })

          }

        },

        abstract: true,

        url:"/shop",

        templateUrl:"templates/shop/list.html",

        controller:"ShopListController"

    })

    使用abstract屬性有什么用,官方說明:abstract: true 表明此狀態(tài)不能被顯性激活,只能被子狀態(tài)隱性激活。不能顯性激活即不能直接通過"/shop"訪問此狀態(tài)路由,那不就是一條死路嗎?那要你何用。等等,我們再看看后面一句:能被子狀態(tài)隱性激活,貌似還能活起來,怎么讓他活起來?我們再看下面的代碼:

    .state('shop.main',{

       url:"/:id",

       abstract: true,

        templateUrl:"templates/shop/main2.html",

        controller:"ShopMainController" 

     })

    狀態(tài):"shop.main"是shop的子狀態(tài),按理論shop.main可以激活shop,我們只需要這樣去訪問:/shop/1,這樣我們可以激活shop狀態(tài),和"shop.main"

    我們暫且不著急,我再再給加上abstract屬性,玩點刺激的,我們再把激活點再往后一級看下面代碼:

    .state('shop.main.info',{

      url:"",

      templateUrl:"templates/shop/info.html",

      cache:'false',

      controller:"InfoController"

    })

    .state('shop.main.author',{

      url:"/author",

      template:"<div>authorauthorauthorauthorauthor</div>"

    })

    .state('shop.main.samebook',{

      url:"samebook",

      template:"<div>samebooksamebooksamebooksamebooksamebooksamebook</div>"

    })

    我看狀態(tài)"shop.main.info"這個狀態(tài) 的url為""所以我們要激活這個狀態(tài)只需要這樣去訪問"shop/1"所有可以做為"shop.main"的一個默認子狀態(tài)。

    此時模塊的嵌套關(guān)系為:list.html嵌套main.html,main.html嵌套info.html。我們可以通過"shop/:id"的url激活這個三層嵌套。

    2.控制器中參數(shù)的使用:

    這個沒什么難點,在控制器中注入"$stateParams" url參數(shù)在這個對象里可以拿得到 :

    shop.controller("ShopMainController",['$scope','$stateParams','$rootScope',function($scope,$stateParams,$rootScope){

      $scope.persons = [1,2,3,4,5,6];

      $scope.good = {

        id:$stateParams.id

      }

      cfpLoadingBar.start();

    }]);

    3.怎么防止模板緩存

    在開發(fā)過程中,模板緩存嚴重影響我們調(diào)試,有時候代碼修改了,模板卻沒有任何變化。很苦惱,其他我們只需要監(jiān)聽下stateChangeSuccess,然后再清除$templateCache就行,這里我們采用run方法添加監(jiān)聽:

    bookApp.run(['$rootScope','$templateCache', function ($rootScope, $templateCache) { 

     var stateChangeSuccess = $rootScope.$on('$stateChangeSuccess', stateChangeSuccess); 

     function stateChangeSuccess($rootScope) { 

      $templateCache.removeAll();  

     } 

    }]);

    以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助。

    更多信息請查看網(wǎng)絡(luò)編程
    易賢網(wǎng)手機網(wǎng)站地址:Angularjs中UI Router的使用方法

    2026上岸·考公考編培訓報班

    • 報班類型
    • 姓名
    • 手機號
    • 驗證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點 | 投訴建議
    工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號:hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)