Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Document $formatters v.1.2.0 -> v.1.3.0: type of value parameter is now a string, not the bound model type #9218

Closed
@wardbell

Description

@wardbell

v.1.3.0-rc.2 broke my zFloat directive which worked fine in v.1.2.0.

Traced to a change in the value passed to a $formatter. It used to be the data-bound value of the model; in 1.3.0, the value is a string.

Here's the plunker: http://plnkr.co/edit/E2HgF7ASNWIdwsvzs5G0?p=preview

Here's the pertinent code fragment from the directive:

return {
    restrict: 'A',
    require: 'ngModel',

    link: function(scope, elm, attr, ngModelCtrl) {
        if (attr.type === 'radio' || attr.type === 'checkbox') return;
        ngModelCtrl.$formatters.push(equivalenceFormatter);

        function equivalenceFormatter(value) { // 1.2.0: integer; 1.3.0: string
           var viewValue = ngModelCtrl.$viewValue // could have used 'elm.val()'
           return (value === +viewValue) ? viewValue : value;
        }
    }

Where the model value was integer 123 in v.1.2.0, it is now the string "123".

Of course the conditional value === +viewValue fails in v.1.3.0 because "123" !== 123

Is that intentional? Please call that out in release notes.

Meanwhile ... fortunately ... a workaround is available for me. I'll just change the conditional to +value === +viewValue which will be compatible with both versions. You may see that in the Plunker by the time you look.

Too bad for everyone else who didn't see this coming.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions