Ответ 1
ngModel
предоставляет свой контроллер ngModelController
API и предлагает вам способ сделать это.
В вашей директиве вы можете добавить $formatters
, которые делают именно то, что вам нужно, и $parsers
, которые делают наоборот (проанализируйте значение до того, как оно поступит в модель).
Вот как вам следует идти:
app.directive('editInPlace', function($filter) {
var dateFilter = $filter('dateFormat');
return {
require: 'ngModel',
restrict: 'E',
scope: { ngModel: '=' },
link: function(scope, element, attr, ngModelController) {
ngModelController.$formatters.unshift(function(valueFromModel) {
// what you return here will be passed to the text field
return dateFilter(valueFromModel);
});
ngModelController.$parsers.push(function(valueFromInput) {
// put the inverse logic, to transform formatted data into model data
// what you return here, will be stored in the $scope
return ...;
});
},
template: '<input type="text" ng-model="ngModel" my-date-picker disabled>'
};
});