SORU
1 AĞUSTOS 2012, ÇARŞAMBA


Nasıl url parametreleri açısal js kullanarak almak için

HTML kaynak kodu

<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>

Angular.js kaynak kodu

<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>

Burada değişkenleri loc ve her iki dönüş loc1testyukarıdaki URL için sonuç olarak. Bu doğru yol mu?

CEVAP
21 Mayıs 2013, Salı


Bu eski bir soru olduğunu biliyorum, ama bana biraz zaman bu tür dışarı seyrek Açısal belgelere verilen sürdü.RouteProviderverouteParamsgitmek için bir yoldur. Rota senin Kumanda/Görüntüleme URL teller ve routeParams denetleyicisi içine geçirilebilir.

Angular seed proje kontrol et. Bu app.js içinde rota sağlayıcı için bir örnek bulabilirsiniz. Parametreler sadece kullanmak için onları bu şekilde ekleyin:

$routeProvider.when('/view1/:param1/:param2', {
    templateUrl: 'partials/partial1.html',    
    controller: 'MyCtrl1'
});

Kumandanız sonra enjekte $routeParams:

.controller('MyCtrl1', ['$scope','$routeParams', function($scope, $routeParams) {
  var param1 = $routeParams.param1;
  var param1 = $routeParams.param2;
  ...
}]);

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • GFX Tutorials

    GFX Tutorial

    12 AĞUSTOS 2013
  • khloe brooks

    khloe brooks

    25 Temmuz 2011
  • olinerd

    olinerd

    23 AĞUSTOS 2007