Skip to content

Directive uses ngModel incorrectly. #9

@jeme

Description

@jeme

Just wanted to point out that this directive is using ngModel somewhat incorrectly,
This means that the $formatters / $parsers pipelines are broken with the directive (it is far from the only directive I have seen that does this btw, so it is a common misunderstanding)

Generally the case can be demonstrated with: https://plnkr.co/edit/0oFTarMU7HEFYnNC5DFf?p=preview
(Note it's not this directive in action, it's just a demonstration of the differences between using require: ngModel vs scope: { ngModel })

$parsers will never be invoked with they way it's implemented here as the ngModel controller that gets bound with this directive just dangles outside of the scope.

We had to fix this in order for the model to be properly updated before the change event is fired.
(no PR for now, just an inline fix, read bellow why)

As a side effect, you won't have to implement a custom ngChange event as that is all taken care off... The drawback here though is that we won't get the previous value with the ng-change event, depending on the scenario there is a workaround, otherwise it's a trivial thing to fix with another custom directive or inline it as a different event.

Because of the minor drawback, I didn't wan't to provide a PR for it just yet.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions