【问题标题】:Change the name of url with Angular使用 Angular 更改 url 的名称
【发布时间】:2017-11-17 19:34:40
【问题描述】:

我有一个用角度制作的网站,其中我想在选择框中的某个选项时更改URL的名称。像这样:

localhost:3000/plumber-in/amsterdam

当城市“乌得勒支”被选中时,Url 必须更改为:

localhost:3000/plumber-in/乌得勒支

这是我的选择框:

<div class="plumber-by-city col-sm-12 home-text-col">
<div class="title-1">Seach by city</div>
<select ng-model="selectedItem" ng-change="change()" ng-options="item as item.city for item in items"></select><span class="fa fa-caret-down"></span>

在我的 app.js 中:

app.config(function($routeProvider, $locationProvider,$animateProvider) {
  $routeProvider

   .when('/plumber-in/:type', {
      templateUrl: 'partials/plumber-by-location.html',
      controller: 'DataCtrl'
   })
});

在我的 controller.js 中:

app.controller('DataCtrl', function($scope,$http,$routeParams){

   $scope.change = function() {
     $scope.type = $routeParams.type;
     console.log($scope.type);
     $rootScope = $scope.selectedItem.city;
     console.log($rootScope);
   };
});

【问题讨论】:

    标签: javascript html angularjs mean


    【解决方案1】:

    快速可行的解决方案将是

    app.controller('DataCtrl', function($scope,$http,$location){
       $scope.change = function() {
           $location.path('/plumber-in/' + $scope.selectedItem.city);
       };
    })
    

    【讨论】:

      猜你喜欢
      • 2011-05-20
      • 2020-09-17
      • 1970-01-01
      • 1970-01-01
      • 2016-03-17
      • 1970-01-01
      • 2015-07-18
      • 2019-01-25
      • 1970-01-01
      相关资源
      最近更新 更多