How prevent angular version earlier than 1.3.0 auto trim for fields?

前端 未结 1 1397
暖寄归人
暖寄归人 2021-01-23 16:20

Is there any way prevent angular version earlier 1.3.0 from auto trim for fields in the whole application? I know that I can prevent it for specified field using ngTrim directiv

相关标签:
1条回答
  • 2021-01-23 16:21

    In Angular prior to 1.3.x you can try to decorate compile function:

    app.config(function($provide) {
        $provide.decorator('inputDirective', function($delegate) {
    
            var directive = $delegate[0];
    
            directive.compile = function(orig) {
                return function(element, attrs, transclude) {
                    attrs.$set('ngTrim', 'false');
                    return orig.apply(null, arguments);
                };
            }(directive.compile);
    
            return $delegate;
        });
    });
    

    This approach should also work in 1.3.x though.

    Demo: http://plnkr.co/edit/gvIa7omiFWwoWW9tyl4S?p=preview

    0 讨论(0)
提交回复
热议问题