Get the URL parameter in Angularjs

Source: Internet
Author: User

Objective:

Angular get through the link form to access the page, to get the parameters in the URL, can not be routed through the way to get, using native JS or jquery, it is more troublesome, fortunately, angular has encapsulated the method to get the URL parameters, and only one line of code to fix, Simple rough, the way to win over traditional URLs to intercept matching strings.

var para= $location. $ $search ["Para"]

Other parameters in the URL are obtained:

//the URL with the # number, see? The URL of the number, see belowurl = http://qiaole.sinaapp.com? #name =CCCCCC$location. Absurl (); //http://qiaole.sinaapp.com? #name =CCCCCC$location. Host (); //qiaole.sinaapp.com$location. Port (); // the$location. Protocol (); //http$location. URL (); //? #name =CCCCCC  //Get URL parameters$location. Search (). Name; //or$location. Search () [' Name ']; //Note: If this is the address: HTTP://QIAOLE.SINAAPP.COM?NAME=CCCCCC  varSearchapp = Angular.module (' Searchapp '), []); Searchapp.config ([' $locationProvider ',function($locationProvider) {$locationProvider. Html5mode (true);  }]); Searchapp.controller (' Mainctrl ', [' $scope ', ' $location ',function($scope, $location) {if($location. Search (). keyword) {$scope. Keyword=$location. Search (). keyword;  }  }]); 

Get the URL parameter in Angularjs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.