AngularJS實(shí)現(xiàn)單一頁面內(nèi)設(shè)置跳轉(zhuǎn)路由的方法
本文實(shí)例講述了AngularJS實(shí)現(xiàn)單一頁面內(nèi)設(shè)置跳轉(zhuǎn)路由的方法。分享給大家供大家參考,具體如下:
單一頁面內(nèi)設(shè)置跳轉(zhuǎn)路由
鑒于現(xiàn)在很多應(yīng)用的應(yīng)用功能以及場(chǎng)景都非常簡單,如果還按照以前的思路,每個(gè)頁面做一個(gè)html,通過路由進(jìn)行跳轉(zhuǎn),不僅在時(shí)間上會(huì)有延遲,在某些特殊的瀏覽器(最典型的如微信內(nèi)置瀏覽器)中,跳轉(zhuǎn)過程中會(huì)出現(xiàn)短暫的白頁。
因此,我們?cè)陂_發(fā)過程中,將頁面邏輯封裝到同一個(gè)html中。當(dāng)系統(tǒng)第一次加載頁面時(shí),將所有頁面全部加載進(jìn)去,然后通過angularJS內(nèi)置的路由進(jìn)行加載。
直接上代碼
聲明app
<script type="text/javascript"> var app = angular.module('ngRouteWxCtb', ['ngRoute','ngCookies']) .config(['$routeProvider', function ($routeProvider) { $routeProvider.when('/0', { templateUrl: '0.html', controller: 'loginCtrl' }).when('/1', { templateUrl: '1.html', controller: '1Ctrl' }).when('/2', { templateUrl: '2.html', controller: '2Ctrl' }).when('/3', { templateUrl: '3.html', controller: '3Ctrl' }).when('/4', { templateUrl: '4.html', controller: '4Ctrl' }).when('/5', { templateUrl: '5.html', // controller: '5Ctrl' }).otherwise({redirectTo: '/login'}); }]); </script>
在頁面中全部加載所有view
<body ng-app="ngRouteWxCtb" class="ng-scope"> <!--用戶登錄-start--> <script type="text/ng-template" id="0.html"> <div> 頁面0 </div> </script> <!--用戶登錄-end--> <!--加入校區(qū)-start--> <script type="text/ng-template" id="1.html"> <div> 頁面1 </div> </script> <!--加入校區(qū)-end--> <!--裁剪圖片-start--> <script type="text/ng-template" id="2.html"> <div> 頁面2 </div> </script> <!--開始上傳圖片 - start--> <script type="text/ng-template" id="3.html"> <div> 頁面3 </div> </script> <!--開始上傳圖片-end--> <!--上傳圖片-start--> <script type="text/ng-template" id="4.html"> <div> 頁面4 </div> </script> <!--上傳圖片-end--> <!--上傳圖片完成-start--> <script type="text/ng-template" id="5.html"> <div> 頁面5 </div> </script> <audio controls="controls" style="display: none;"></audio>
然后通過路由進(jìn)行跳轉(zhuǎn)
app.controller('loginCtrl', function ($scope, $http, $interval, $cookies, $location, userService) { $scope.LoginSucessLocation = function () { var hre = './main#/1'; location.href = hre; } })
更多關(guān)于AngularJS相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《AngularJS指令操作技巧總結(jié)》、《AngularJS入門與進(jìn)階教程》及《AngularJS MVC架構(gòu)總結(jié)》
希望本文所述對(duì)大家AngularJS程序設(shè)計(jì)有所幫助。
- Angular 多級(jí)路由實(shí)現(xiàn)登錄頁面跳轉(zhuǎn)(小白教程)
- Angular 利用路由跳轉(zhuǎn)到指定頁面的指定位置方法
- Angular4.x通過路由守衛(wèi)進(jìn)行路由重定向?qū)崿F(xiàn)根據(jù)條件跳轉(zhuǎn)到相應(yīng)的頁面(推薦)
- AngularJS實(shí)現(xiàn)頁面跳轉(zhuǎn)后自動(dòng)彈出對(duì)話框?qū)嵗a
- AngularJS頁面帶參跳轉(zhuǎn)及參數(shù)解析操作示例
- angular同一頁面跳轉(zhuǎn)重新執(zhí)行的實(shí)現(xiàn)方法
相關(guān)文章
詳談AngularJs 控制器、數(shù)據(jù)綁定、作用域
下面小編就為大家?guī)硪黄斦凙ngularJs 控制器、數(shù)據(jù)綁定、作用域。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-07-07AngularJS實(shí)現(xiàn)使用路由切換視圖的方法
這篇文章主要介紹了AngularJS實(shí)現(xiàn)使用路由切換視圖的方法,結(jié)合學(xué)生信息管理系統(tǒng)為例分析了使用controllers.js控制器來切換視圖的具體步驟與相關(guān)操作技巧,需要的朋友可以參考下2017-01-01詳解在AngularJS的controller外部直接獲取$scope
本篇文章主要介紹了詳解在AngularJS的controller外部直接獲取$scope ,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06Ionic + Angular.js實(shí)現(xiàn)圖片輪播的方法示例
圖片輪播在我們?nèi)粘i_發(fā)中是再熟悉不過的了,下面這篇文章主要給大家介紹了Ionic + Angular實(shí)現(xiàn)圖片輪播的方法,文中給出了詳細(xì)的示例代碼供大家參考學(xué)習(xí),需要的朋友們下面來一起看看吧。2017-05-05