Angular.js and HTML5 date input value — how to get Firefox to show a readable date value in a date input?

前端 未结 7 2003
無奈伤痛
無奈伤痛 2020-12-12 13:26

I have an HTML5 date input and I would like its value to be set to the value of the date property in my model by default. I\'m not too fussy about formatting since Chrome se

7条回答
  •  隐瞒了意图╮
    2020-12-12 14:29

    I've used ng-change:

    Date.prototype.addDays = function(days) {
      var dat = new Date(this.valueOf());
      dat.setDate(dat.getDate() + days);
      return dat;
    }
    
    var app = angular.module('myApp', []);
    
    app.controller('DateController', ['$rootScope', '$scope',
      function($rootScope, $scope) {
        function init() {
          $scope.startDate = new Date();
          $scope.endDate = $scope.startDate.addDays(14);
        }
    
    
        function load() {
          alert($scope.startDate);
          alert($scope.endDate);
        }
    
        init();
        // public methods
        $scope.load = load;
        $scope.setStart = function(date) {
          $scope.startDate = date;
        };
        $scope.setEnd = function(date) {
          $scope.endDate = date;
        };
    
      }
    ]);
    
    
    Start

提交回复
热议问题