• <fieldset id="8imwq"><menu id="8imwq"></menu></fieldset>
  • <bdo id="8imwq"><input id="8imwq"></input></bdo>
    最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
    問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
    當前位置: 首頁 - 科技 - 知識百科 - 正文

    AngularJS使用ui-route實現多層嵌套路由

    來源:懂視網 責編:小OO 時間:2020-11-27 20:06:42
    文檔

    AngularJS使用ui-route實現多層嵌套路由

    一、預期實現效果。https://liyuan-meng.github.io/uiRouter-app/index.html。(項目地址:https://github.com/liyuan-meng/uiRouter-app)。二、分析題目要求,給出依賴關系,構建項目。1.service。(1)根據條件查詢people數據checkPeople.service,不給出條件則查詢所有。(2)得到路由信息getStateParams.service。2.components。(1)hello模塊:點擊button按鈕更改內容。(2)peolpleList模塊:顯示people列表,點擊people顯示people詳情。依賴于checkPeople.service模塊。
    推薦度:
    導讀一、預期實現效果。https://liyuan-meng.github.io/uiRouter-app/index.html。(項目地址:https://github.com/liyuan-meng/uiRouter-app)。二、分析題目要求,給出依賴關系,構建項目。1.service。(1)根據條件查詢people數據checkPeople.service,不給出條件則查詢所有。(2)得到路由信息getStateParams.service。2.components。(1)hello模塊:點擊button按鈕更改內容。(2)peolpleList模塊:顯示people列表,點擊people顯示people詳情。依賴于checkPeople.service模塊。
    本文主要介紹了AngularJS使用ui-route實現多層嵌套路由的示例,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧,希望能幫助到大家。

    一、預期實現效果:

    https://liyuan-meng.github.io/uiRouter-app/index.html

    (項目地址:https://github.com/liyuan-meng/uiRouter-app)

    二、分析題目要求,給出依賴關系,構建項目

    1. service:

    (1)根據條件查詢people數據checkPeople.service,不給出條件則查詢所有。

    (2)得到路由信息getStateParams.service。

    2. components:

    (1)hello模塊:點擊button按鈕更改內容。

    (2)peolpleList模塊:顯示people列表,點擊people顯示people詳情。依賴于checkPeople.service模塊。

    (3)peopleDetail模塊:顯示people詳情,依賴于checkPeople.service模塊和getStateParams.service模塊。

    3. 構建項目:

    如圖所示:component目錄用來保存所有服務模塊和業務模塊,lib目錄保存外部引用(我是用的是angular.js1.5.8和ui-route0.2.18),app.config.js文件用來配置路由,index.html則作為入口文件。

    三、實現這個例子

    1. 首頁index.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
     <meta charset="UTF-8">
     <title>Title</title>
     <script src="./lib/angular.js"></script>
     <script src="./lib/angular-ui-route.js"></script>
     <script src="./app.config.js"></script>
     <script src="./components/core/people/checkPeople.service.js"></script>
     <script src="./components/core/people/getStateParams.service.js"></script>
     <script src="./components/hello/hello.component.js"></script>
     <script src="./components/people-list/people-list.component.js"></script>
     <script src="./components/people-detail/people-detail.component.js"></script>
    </head>
    <body ng-app="helloSolarSystem">
    <p>
     <a ui-sref="helloState">Hello</a>
     <a ui-sref="aboutState">About</a>
     <a ui-sref="peopleState">People</a>
    </p>
    
    <ui-view></ui-view>
    
    </body>
    </html>

    (1)導入lib中的文件以及所有用到的service和component服務的文件。

    (2)ng-app="helloSolarSystem"指明了從helloSolarSystem模塊開始解析。

    (3)定義視圖<ui-view></ui-view>

    2. 配置路由app.config.js

    (1)模塊名字:helloSolarSystem;

    (2)注入'peopleList', 'peopleDetail', 'hello','ui.router'模塊。

    (3)配置stateProvider服務的視圖控制,例如第一個名為helloState的視圖控制器:當ui-sref == "helloState"的時候,路由更新為url的值#/helloState,并且<ui-view></ui-view>中顯示的內容為<hello></hello>組件解析出的內容。

    (4)嵌套路由的實現:名為peopleState的視圖控制器是父路由。名為peopleState.details的視圖控制器是子路由。這是一種相對路由方式,父路由將匹配.../index.html#/peopleState/,子路由將匹配.../index.html#/peopleState/detail/x(x是/detail/:id中的id的值)。如果改成絕對路由的形式,只需要寫成url:'^/detail/:id',這時子路由將匹配.../index.html#/detail/x(x是/detail/:id中的id的值)。

    4. 實現checkPeople.service(根據條件查找people)

    checkPeople.sercice.js

    (1)在getData這個函數中,我們想要返回一個保存people信息的數組,但是由于使用$http().then()服務的時候,這是一個異步請求,我們并不知道請求什么時候結束,所以世界返回people數組是有問題的。我們注意到,$http().then()是一個Promise對象,所以我們可以想到直接將這個對象返回,這樣在就可以使用"函數的結果.then(function(data))"來得到異步請求拿來的數據data。

    3. 實現getStateParams.service(獲取路由信息)

    getStatePatams.service.js

    (1)這里的getParams函數返回的是路由信息的最后一個數據,也就是people的id,這個service有些特殊,不夠通用,可能還需要優化一下會更加合理。不過并不影響我們的需求。

    4. 實現hello模塊

    hello.template.html

    <p>
     <p ng-hide="hideFirstContent">hello solar sytem!</p>
     <p ng-hide="!hideFirstContent">whats up solar sytem!</p>
     <button ng-click="ctlButton()">click</button>
    </p>

    hello.component.js

    5. 實現peolpeList模塊:

    peopleList.template.html

    <p>
     <ul>
     <a ng-repeat="item in people" ui-sref="peopleState.details({id:item.id})">
     <li>{{item.name}}</li>
     </a>
     </ul>
     <ui-view></ui-view>
    </p>

    (1)這里的<ui-view></ui-view>用來顯示peopleList的子組件pepleDetail

    peopleList.component.js

    6. 實現peopleDetail模塊

    peopleDetail.template.html

    <ul ng-repeat="item in peopleDetails track by $index">
     <li>名字: {{item.name}}</li>
     <li>介紹: {{item.intro}}</li>
    </ul>

    peopleDetail.component.js

    7.源碼:https://github.com/liyuan-meng/uiRouter-app

    聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

    文檔

    AngularJS使用ui-route實現多層嵌套路由

    一、預期實現效果。https://liyuan-meng.github.io/uiRouter-app/index.html。(項目地址:https://github.com/liyuan-meng/uiRouter-app)。二、分析題目要求,給出依賴關系,構建項目。1.service。(1)根據條件查詢people數據checkPeople.service,不給出條件則查詢所有。(2)得到路由信息getStateParams.service。2.components。(1)hello模塊:點擊button按鈕更改內容。(2)peolpleList模塊:顯示people列表,點擊people顯示people詳情。依賴于checkPeople.service模塊。
    推薦度:
    標簽: 實現 js 路由
    • 熱門焦點

    最新推薦

    猜你喜歡

    熱門推薦

    專題
    Top
    主站蜘蛛池模板: 精品久久久久久国产潘金莲| 亚洲国产精品久久久天堂| 国内精品久久久久久麻豆| 久久精品无码专区免费青青| 国内精品久久久久久中文字幕| 91国内外精品自在线播放| 亚洲日韩精品一区二区三区| 精品欧美一区二区在线观看| 四虎国产精品免费久久久| 99精品视频在线观看免费| 无码少妇精品一区二区免费动态| 精品国产成人国产在线观看| 亚洲国产成人精品不卡青青草原| 国产精品日本一区二区在线播放| 中文字幕亚洲精品无码| 欧美日韩国产成人高清视频,欧美日韩在线精品一 | 精品免费久久久久国产一区| 国产精品久久久久久福利69堂| 亚洲AV无码精品色午夜在线观看| 久久精品一区二区影院| 国产精品欧美亚洲韩国日本久久 | 精品久久人人妻人人做精品| 2021国产精品视频网站| 久久国产精品-久久精品| 500av大全导航精品| 精品福利一区二区三区免费视频| 亚洲AV日韩精品久久久久| 亚洲国产精品久久电影欧美| 亚洲日韩国产AV无码无码精品| 久久精品国产黑森林| 精品久久久无码中文字幕| 久草热久草热线频97精品| 久久e热在这里只有国产中文精品99| 国产精品青草久久久久福利99 | 精品亚洲永久免费精品| 国产人成精品午夜在线观看| 国产91精品在线观看| 精品成人免费自拍视频| 久久久国产精品福利免费| 91亚洲国产成人久久精品网址 | 国产一级精品高清一级毛片|