相关疑难解决方法(0)

AngularJS - 在自定义指令中呈现模板之前格式化ng-model

我正在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)

但这给了我一个错误.这该怎么做?

templates model directive angularjs

11
推荐指数
1
解决办法
1万
查看次数

标签 统计

angularjs ×1

directive ×1

model ×1

templates ×1