根据日期选取器的值angular.js动态更改URL

时间:2014-04-14 10:44:50

标签: javascript angularjs angular-ui angular-ui-bootstrap

<label>From</label>
<input type="text" datepicker-popup="dd-MM-yyyy" ng-model="StartDate"/>
<label>To</label>
<input type="text" datepicker-popup="dd-MM-yyyy" ng-model="EndDate"/>   

网址路径为:

GET /admin/api/stats controllers.AdminStatsApi.get(start: Option[LocalDate], end: Option[LocalDate], computeDiff: Boolean ?= false)

我的问题是如何根据datepicker中输入的日期(值)更改网址。

1 个答案:

答案 0 :(得分:0)

您提供的信息不足。你用什么? UI的路由器? $位置?

但基本上你可以这样做:

var changeUrl = function(startDate, endDate){
  //do url change with whatever thing you are using to change your url
}

$scope.$watch('StartDate', function(newValue){
   var start = newValue;
   var end = $scope.endDate;

   //do your url change here
   changeUrl(start, end);
}, true);


$scope.$watch('EndDate', function(newValue){
   var start = $scope.startDate;
   var end = newValue;

   //do your url change here
   changeUrl(start, end);
}, true);