私はこのカスタムコンポーネント書いた:それはHTML5の検証日付入力に必要としてカスタムアングル1.5コンポーネントで日付入力max属性を動作させる方法は?
<datetime value="vm.woComplete.CompleteDate" max="2016-10-25"></datetime>
最大属性doesntの仕事を。
なぜ?
// DateTimeComponent is used for date/time input with 2-way binding and UTC correction
namespace AppDomain {
"use strict";
class DateTimeController {
value: Date;
displayValue: Date;
max: string;
static $inject = ["$scope"];
// West from UTC - TimezoneOffset is positive , East from UTC - TimezoneOffset is negative
constructor($scope: ng.IScope) {
$scope.$watch(
"$ctrl.displayValue",
(newValue: Date, oldValue: Date) => {
this.value = newValue;
var offset = this.displayValue.getTimezoneOffset()/60; // getTimezoneOffset returns minutes, we need hours
this.value.setHours(this.value.getHours() + offset); // LOCAL to UTC = UTC + Offset
}
);
}
$onInit() {
this.displayValue = this.value;
var offset = this.displayValue.getTimezoneOffset()/60; // getTimezoneOffset returns minutes, we need hours
this.displayValue.setHours(this.displayValue.getHours() - offset); // UTC to LOCAL = UTC - Offset
}
}
const DateTimeComponent: ng.IComponentOptions = {
//template: "<p><input type='date' class='form-control' ng-model='$ctrl.displayValue'></p><p><input type='time' class='form-control' ng-model='$ctrl.displayValue'></p>",
template: "<p><input type='datetime-local' class='form-control' ng-model='$ctrl.displayValue' max='{{$ctrl.max}}'></p>",
bindings: {
value: "=",
max: "@"
},
controller: DateTimeController
};
angular.module("app").component("datetime", DateTimeComponent);
}
Plunker:http://plnkr.co/edit/iYt0sS?p=preview