我有这个angular.directive
V1.App.directive('v1DatePicker', ['$compile', function ($compile) {
return {
restrict: "E",
require: [
'ngModel'
],
isolated:true,
scope: {
id: '@',
ngModel: '='
},
link: function(scope, element, attrs, requireds) {
},
template: '<md-datepicker id="id" ' +
' ng-model="internalValue" ' +
' md-placeholder="DD/MM/YYYY"></md-datepicker>'
}
}]).directive('v1MonthPicker', ['$compile', function ($compile) {
return {
restrict: "E",
require: [
'ngModel'
],
isolated:true,
scope: {
id: '@',
ngModel: '='
},
link: function(scope, element, attrs, requireds) {
},
template: '<md-datepicker id="id" ' +
' ng-model="internalValue" ' +
' md-placeholder="MM/YYYY"></md-datepicker>'
}
}]).config(['$mdDateLocaleProvider', function ($mdDateLocaleProvider) {
$mdDateLocaleProvider.formatDate = function (date) {
return date ? moment(date).format('DD/MM/YYYY') : '';
};
$mdDateLocaleProvider.parseDate = function (dateString) {
var m = moment(dateString, 'DD/MM/YYYY', true);
return m.isValid() ? m.toDate() : new Date(NaN);
};
}]);
我的观点是:我如何定义两个不同的formatDate和parseDate?这两个指令都是一样的,我只想在第一个选择日期时,我看到例如23/03/2018和第二个03/2018。 有可能吗?
感谢大家。