ng_change doesn't copy time value of angular-moment-picker into other fields

237 views Asked by At

I have a dynamically generated form with a time field which is filled in with angular-moment-picker. I want this value to be copied to the other time fields using a function assigned to ng_change. Currently this function is not called however my input field includes ng_change. When I don't use moment-picker then value is copied without any issues. input field:

@Html.TextBoxFor(model => model.Mymodels.Model[i].Time,
                        new
                        {
                            @class = "form-control",
                            ng_Model = "Model_Time" + (i + 1),
                            ng_change = "copyTime(" + (i + 1) + ")",
                            moment_picker = "Model_Time" + (i + 1),
                            format = "LT",
                            locale = "nl",
                            ng_model_options = "{ updateOn: 'blur' }",
                            set_on_select = true
                        })

Copy function:

  $scope.copyTime = function (index) {
        console.log("Check if function is called");
        $scope.Model_Time2 = $scope.Model_Time1;
        $scope.Model_Time3 = $scope.Model_Time1;
        $scope.Model_Time4 = $scope.Model_Time1;
};
1

There are 1 answers

2
Frank Modica On BEST ANSWER

According to the docs, it has its own function called change:

@Html.TextBoxFor(model => model.Mymodels.Model[i].Time,
                        new
                        {
                            change = "copyTime(" + (i + 1) + ")"
                            // ...
                        })

That said, if angular-moment is using ngModelController underneath to update the model, I'd have expected ng-change to work as well since it is invoked automatically once the model has changed. Maybe it doesn't play nice with ng-model-options?