angularJS1 url中攜帶參數(shù)的獲取方法
index.html 從此界面跳轉(zhuǎn)到a.html界面
<!doctype html> <html> <head> <meta charset="utf-8"> <title>form demo</title> <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0" /> <script src="js/angular.min.1.6.0.js"></script> </head> <body ng-app="app" ng-controller="myctrl"> <button ng-click="jump()" >點(diǎn)擊跳轉(zhuǎn)下一頁(yè)</button> <br /><br /> <a ng-href="a.html?name=xie&age=25&gender=nv" rel="external nofollow" >點(diǎn)擊跳轉(zhuǎn)下一頁(yè)</a> </div> </body> <script> var app = angular.module('app', []); app.controller('myctrl', function($scope, $window) { $scope.jump = function() { $window.location.href = 'a.html?name=xie&age=25&gender=nv'; } }); </script> </html>
a.html 跳轉(zhuǎn)到的目標(biāo)界面,在此界面獲取url攜帶的參數(shù):
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0" /> <script src="js/angular.min.1.6.0.js"></script> <title></title> </head> <body ng-app="myapp" ng-controller="myctrl" > <p>a.html</p> </body> <script> //Url="http://168.33.222.69:8020/angularjs_demo/a.html?name=xie&age=25&gender=nv"; var app=angular.module("myapp",[]); app.config(['$locationProvider', function($locationProvider) { // $locationProvider.html5Mode(true); $locationProvider.html5Mode({ enabled: true, requireBase: false }); }]); app.controller('myctrl', function($scope, $location) { console.log($location.search().name); console.log($location.search().age); console.log($location.search().gender); }); //打印結(jié)果: //[Web瀏覽器] "xie" //[Web瀏覽器] "25" //[Web瀏覽器] "nv" </script> </html>
以上這篇angularJS1 url中攜帶參數(shù)的獲取方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
angularjs實(shí)現(xiàn)搜索的關(guān)鍵字在正文中高亮出來(lái)
這篇文章主要介紹了angularjs實(shí)現(xiàn)搜索的關(guān)鍵字在正文中高亮出來(lái),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06AngularJs html compiler詳解及示例代碼
本文主要介紹AngularJs html compiler的知識(shí)講解,這里整理了相關(guān)資料及相關(guān)示例代碼,有興趣的小伙伴可以參考下2016-09-09AngularJS實(shí)現(xiàn)表單驗(yàn)證功能
這篇文章主要為大家詳細(xì)介紹了AngularJS實(shí)現(xiàn)表單驗(yàn)證功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-01-01AngularJS基礎(chǔ) ng-repeat 指令簡(jiǎn)單示例
本文主要講解AngularJS ng-repeat 指令,這里對(duì)ng-repeat的基礎(chǔ)資料做了整理,并附有示例代碼,有興趣的朋友可以參考下2016-08-08詳解Angular Karma測(cè)試的持續(xù)集成實(shí)踐
這篇文章主要介紹了詳解Angular Karma測(cè)試的持續(xù)集成實(shí)踐,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11Angular?Tree?Shaking優(yōu)化機(jī)制原理詳解
這篇文章主要為大家介紹了Angular?Tree?Shaking優(yōu)化機(jī)制原理詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-10-10Angularjs驗(yàn)證用戶輸入的字符串是否為日期時(shí)間
這篇文章主要介紹了Angularjs驗(yàn)證用戶輸入的字符串是否為日期時(shí)間,需要的朋友可以參考下2017-06-06