0

I'm trying to write formatter and parser through a directive.

angular.module('myModule').directive('toDate', function(){
        debugger; //Debugger Not Coming Here
        return{
            require: 'ngModel',
            link: function(scope, element, attr, ngModel){
                debugger; //Debugger Not Coming Here Too
                ngModel.$formatters.push(function(value){
                        return new Date(value);
                });

                ngModel.$parsers.push(function(value){
                    if(typeof value === 'object'){
                        return value.getTime();
                    }
                });

            }
        };
    });

using it in view :

 <td><input type="text"  ng-model="item.s_modified_on" toDate /></td>

It is not working.

1 Answer 1

3

Use

 <td><input type="text"  ng-model="item.s_modified_on" to-date /></td>

instead of

 <td><input type="text"  ng-model="item.s_modified_on" toDate /></td>

Directives have camel cased names such as ngBind. The directive can be invoked by translating the camel case name into snake case with these special characters :, -, or _. Optionally the directive can be prefixed with x-, or data- to make it HTML validator compliant.

Reference: https://docs.angularjs.org/guide/directive

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.