Skip to content

Ignoring model changes if model is set to string #305

@easyest

Description

@easyest

Input:

                <input class="form-control"
                       name="MomentPicker"
                       ng-model="vm.testDateTime"
                       ng-model-options="{ updateOn: 'blur' }"
                       moment-picker="vm.testDateTime">

If model is set to string - it is ignored. See Plunkr

I have no TS coding experience, so I made changes to JS directly. See Plunkr

The change I made is adding one more watcher after the watcher if ($attrs['ngModel'] != $attrs['momentPicker']):

                $scope.$watch('model', function (newValue, oldValue) {
                    if (typeof newValue === "string") {
                        newValue = moment(newValue);
                    }
                    if (newValue !== oldValue)
                        utility_1.setValue(newValue, $scope, $ctrl, $attrs);
                });

You can check the exact change at this comit

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