使用AngularJS筛选日期

使用AngularJS筛选日期,angularjs,Angularjs,我想使用日期创建一个自定义AngularJS过滤器,但首先我的过滤器不起作用 app.filter('calculEndDate',function(){ //这里我想在日期上加上“持续时间” //根据“持续时间类型”的月份或年份 返回函数(日期){ 返回日期; } }); 月 年 起始日期 将参数添加到过滤器: app.filter('calculEndDate', function() { // here I want to add "duration" to the dat

我想使用日期创建一个自定义AngularJS过滤器,但首先我的过滤器不起作用

app.filter('calculEndDate',function(){
//这里我想在日期上加上“持续时间”
//根据“持续时间类型”的月份或年份
返回函数(日期){
返回日期;
}
});

月
年
起始日期

将参数添加到过滤器:

app.filter('calculEndDate', function() {
      // here I want to add "duration" to the date
      // month or year according to "durationType"
      return function(date,duration, durationType) {
            //your code managing duration and durationType
      }
});


<select ng-model="durationType">
      <option>month</option>
      <option>year</option>
</select>
<input type="number" ng-model="duration">
<label for="startDate">startDate</label>
<input type="text" ng-model="startDate">
<input type="text" ng-value="startDate | calculEndDate : duration : durationType">
app.filter('calculEndDate',function(){
//这里我想在日期上加上“持续时间”
//根据“持续时间类型”的月份或年份
返回函数(日期、持续时间、持续时间类型){
//您的代码管理duration和durationType
}
});
月
年
起始日期

将参数添加到过滤器:

app.filter('calculEndDate', function() {
      // here I want to add "duration" to the date
      // month or year according to "durationType"
      return function(date,duration, durationType) {
            //your code managing duration and durationType
      }
});


<select ng-model="durationType">
      <option>month</option>
      <option>year</option>
</select>
<input type="number" ng-model="duration">
<label for="startDate">startDate</label>
<input type="text" ng-model="startDate">
<input type="text" ng-value="startDate | calculEndDate : duration : durationType">
app.filter('calculEndDate',function(){
//这里我想在日期上加上“持续时间”
//根据“持续时间类型”的月份或年份
返回函数(日期、持续时间、持续时间类型){
//您的代码管理duration和durationType
}
});
月
年
起始日期

将参数添加到过滤器:

app.filter('calculEndDate', function() {
      // here I want to add "duration" to the date
      // month or year according to "durationType"
      return function(date,duration, durationType) {
            //your code managing duration and durationType
      }
});


<select ng-model="durationType">
      <option>month</option>
      <option>year</option>
</select>
<input type="number" ng-model="duration">
<label for="startDate">startDate</label>
<input type="text" ng-model="startDate">
<input type="text" ng-value="startDate | calculEndDate : duration : durationType">
app.filter('calculEndDate',function(){
//这里我想在日期上加上“持续时间”
//根据“持续时间类型”的月份或年份
返回函数(日期、持续时间、持续时间类型){
//您的代码管理duration和durationType
}
});
月
年
起始日期

将参数添加到过滤器:

app.filter('calculEndDate', function() {
      // here I want to add "duration" to the date
      // month or year according to "durationType"
      return function(date,duration, durationType) {
            //your code managing duration and durationType
      }
});


<select ng-model="durationType">
      <option>month</option>
      <option>year</option>
</select>
<input type="number" ng-model="duration">
<label for="startDate">startDate</label>
<input type="text" ng-model="startDate">
<input type="text" ng-value="startDate | calculEndDate : duration : durationType">
app.filter('calculEndDate',function(){
//这里我想在日期上加上“持续时间”
//根据“持续时间类型”的月份或年份
返回函数(日期、持续时间、持续时间类型){
//您的代码管理duration和durationType
}
});
月
年
起始日期
var-app=angular.module(“app”,[]);
app.filter('calculEndDate',function(){
//这里我想在日期上加上“持续时间”
//根据“持续时间类型”的月份或年份
返回函数(日期、持续时间、持续时间类型){
var日期=新日期(日期);
如果(持续时间和持续时间类型==“月”)
date.setMonth(date.getMonth()+持续时间);
如果(持续时间和持续时间类型==“年”)
date.setFullYear(date.getFullYear()+持续时间)
返回日期;
}
});

月
年
起始日期
{{startDate | CalculateDate:duration:durationType}
var-app=angular.module(“app”,[]);
app.filter('calculEndDate',function(){
//这里我想在日期上加上“持续时间”
//根据“持续时间类型”的月份或年份
返回函数(日期、持续时间、持续时间类型){
var日期=新日期(日期);
如果(持续时间和持续时间类型==“月”)
date.setMonth(date.getMonth()+持续时间);
如果(持续时间和持续时间类型==“年”)
date.setFullYear(date.getFullYear()+持续时间)
返回日期;
}
});

月
年
起始日期
{{startDate | CalculateDate:duration:durationType}
var-app=angular.module(“app”,[]);
app.filter('calculEndDate',function(){
//这里我想在日期上加上“持续时间”
//根据“持续时间类型”的月份或年份
返回函数(日期、持续时间、持续时间类型){
var日期=新日期(日期);
如果(持续时间和持续时间类型==“月”)
date.setMonth(date.getMonth()+持续时间);
如果(持续时间和持续时间类型==“年”)
date.setFullYear(date.getFullYear()+持续时间)
返回日期;
}
});

月
年
起始日期
{{startDate | CalculateDate:duration:durationType}
var-app=angular.module(“app”,[]);
app.filter('calculEndDate',function(){
//这里我想在日期上加上“持续时间”
//根据“持续时间类型”的月份或年份
返回函数(日期、持续时间、持续时间类型){
var日期=新日期(日期);
如果(持续时间和持续时间类型==“月”)
date.setMonth(date.getMonth()+持续时间);
如果(持续时间和持续时间类型==“年”)
date.setFullYear(date.getFullYear()+持续时间)
返回日期;
}
});

月
年
起始日期
{{startDate | CalculateDate:duration:durationType}

如果有问题,请让我知道我的答案是否通过接受或评论解决了您的问题:)如果有问题,请让我知道我的答案是否通过接受或评论解决了您的问题:)如果有问题,请让我知道我的答案是否通过接受或评论解决了您的问题:)请让我知道知道我的回答是否解决了您的问题,如果有问题,请接受或评论:)