更改后URL参数消失(删除)

时间:2016-04-05 05:14:14

标签: angularjs angular-ui-router

如视频所示,更改后的更改的url参数将消失(清除/删除)。

  

https://youtu.be/06aHXdNl7J8

例如,当我在下拉列表中选择台北时,网址应为

  

http://localhost:3003/user/quick_search/index?departure_name=TAIPEI

但它只会持续很短的时间,

然后它返回到原始网址http://localhost:3003/user/quick_search/index

对于我的用例,参数是多个且是可选的,我正在进行URL parametersFORM control的双向绑定

更新

例如,如果我选择CHIANGMAI作为离开,它似乎首先工作。该网址为http://133.130.101.114:3000/user/quick_search/index#/?departure_name=CHIANGMAI

但是,它会很快恢复为http://133.130.101.114:3000/user/quick_search/index#/

这是演示网站http://133.130.101.114:3000/user/quick_search/index#/

App config

app.config(['$routeProvider', '$locationProvider', function(routeProvider, locationProvider) {
  routeProvider.
    when('/',
      {
        templateUrl: 'quick_search/form.html',
        controller: 'form_ctrl'
      }
    ).
    otherwise(
      {
        templateUrl: 'quick_search/form.html',
        controller: 'form_ctrl'
      }
    );

  locationProvider.html5Mode({
    enabled: true,
  });

}]);

Form_Controller.js(更改下拉选项后更改URL参数)

  $scope.updateDeparture = function(departure){
    if ( ! (typeof departure === 'undefined' || departure === null) ){
      $scope.departure_name = departure.name;
    }
  }

  $scope.$watch("departure_name", function(newValue) {
      $location.search("departure_name", newValue);
  });

0 个答案:

没有答案
相关问题