在angularJS中注入$ filter时出错

时间:2017-08-20 17:20:28

标签: javascript angularjs

我正在尝试使用http://jsfiddle.net/phaas/8jFpV/。注入$filter

时出错
// Converts value parameter from yyyyMMdd into yyyy/MM/dd format and vice versa
app.directive('DateConverter', function($compile, $filter) {
    return {
        restrict: 'A',
        require: 'ngModel',
        link: function(scope, element, attr, ngModel) {

            function fromUser(text) {
                var value = $filter('date')(text, "yyyyMMdd");
                return value;
            }

            function toUser(text) {
                var value = $filter('date')(text, "short");
                return value;               
            }

            ngModel.$parsers.push(fromUser);
            ngModel.$formatters.push(toUser);
        }
    };
});
  

angular.js:4387未捕获错误:[$ injector:modulerr]       在angular.js:38       在angular.js:4387       在m(angular.js:336)       在g(angular.js:4348)       在eb(angular.js:4274)       在d(angular.js:1630)       在Ac(angular.js:1651)       在Zd(angular.js:1545)       在angular.js:28361       在HTMLDocument.a(angular.js:2998)

1 个答案:

答案 0 :(得分:1)

将名称 DateConverter 更改为 dateConverter 命名不正确需要在camelCase中。