我正在Angular JS中创建一个自定义指令.我想在模板渲染之前格式化ng-model.
这是我到目前为止:
app.js
app.directive('editInPlace', function() {
return {
require: 'ngModel',
restrict: 'E',
scope: { ngModel: '=' },
template: '<input type="text" ng-model="ngModel" my-date-picker disabled>'
};
});
Run Code Online (Sandbox Code Playgroud)
HTML
<edit-in-place ng-model="unformattedDate"></edit-in-place>
Run Code Online (Sandbox Code Playgroud)
我想在将unformattedDate值输入模板的ngModel之前格式化.像这样的东西:
template: '<input type="text" ng-model="formatDate(ngModel)" my-date-picker disabled>'
Run Code Online (Sandbox Code Playgroud)
但这给了我一个错误.这该怎么做?