HTMLCome ottenere i parametri URL utilizzando AngularJS
<div ng-app="">
<div ng-controller="test">
<div ng-address-bar browser="html5"></div>
<br><br>
$location.url() = {{$location.url()}}<br>
$location.search() = {{$location.search('keyword')}}<br>
$location.hash() = {{$location.hash()}}<br>
keyword valus is={{loc}} and ={{loc1}}
</div>
</div>
AngularJS codice sorgente
<script>
function test($scope, $location) {
$scope.$location = $location;
$scope.ur = $scope.$location.url('www.html.com/x.html?keyword=test#/x/u');
$scope.loc1 = $scope.$location.search().keyword ;
if($location.url().indexOf('keyword') > -1){
$scope.loc= $location.url().split('=')[1];
$scope.loc = $scope.loc.split("#")[0]
}
}
</script>
Qui le variabili loc
e loc1
entrambi restituiscono prova come risultato per l'URL sopra. È questo il modo corretto?
Si consiglia di controllare [$ routeParams] (http://docs.angularjs.org/api/ng.$routeParams). –
Non è chiaro cosa stai chiedendo qui ... i $ routeParams e $ location # metodi doc dovrebbero farti iniziare – deck
Ti preghiamo di considerare l'aggiunta di un commento al momento del voto basso in modo che la domanda possa essere migliorata. Grazie. – praveenpds