简体   繁体   中英

AngularJs input Week - Show current CalendarWeek / Add 10 days to Current Calender Week

I am quite new to Angular and facing some problems atm.

Here is what I want to build:

  1. I want to show the current Date: yyyy-MM-ss (Works)
  2. I want to show the current Calendar Week: yyyy-Www (Doesn't Work)
  3. On button ng-click, I want to add 10 days to todays date. (Works only for 1)

CODE: JSFiddle

HTML

<div ng-controller="MyCtrl">
<div>
    DateToday<br>
    <input type="date" placeholder="yyyy-MM-dd" value="{{today | date :'yyyy-MM-dd'}}"><br><br>

    CalendarWeek:<br>
    <input type="week" placeholder="YYYY-W##" value="{{today | date :'yyyy-Www'}}"/><br><br>

    <input ng-click="add10Days()" value="Add 10 Days" type="button"/>
  </div>
</div>

JS/AngularJS:

var myApp = angular.module('myApp',[]);

function MyCtrl($scope) {

$scope.today = new Date();

$scope.add10Days = function () {
      var numberOfDaysToAdd = 10;
      $scope.today.setDate($scope.today.getDate() + numberOfDaysToAdd);
  }; 
});

I think it has something todo with the week format yyyy-w## or maybe with the browser (Chrome) I am using. Help would be much appreciated :)

Thanks

  1. 'ww' date filter only works in Angular 1.3 and on. I see you're on 1.0.1
  2. Seems to work fine in the fiddle. GIF below:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM