thomas
thomas

Reputation: 1281

angularjs - bootbox callback issue

I have a view with two tabs, in first tab I have the text input commentaireLien.

In the controller, when I enter in the bootbox confirm callback , the input commentaireLiens is not refreshed(with "test") in the browser.
If I go in another tab in the view and then go back in the tab that contains commentaireLiens, then it gets refreshed.

I don't understand why.

bootbox.confirm({
    size: "small",
    message: "Voulez-vous valider le CV ?",
    callback: function (result) {
        if (result) {
            vm.commentaireLiens ="test";
        } 
    }
})
<input type="text" class="form-control" name="commentaireLiens"
       id="field_commentaireLiens"
       ng-model="vm.commentaireLiens"
/>

Upvotes: 0

Views: 80

Answers (1)

georgeawg
georgeawg

Reputation: 48968

bootbox.confirm({
    size: "small",
    message: "Voulez-vous valider le CV ?",
    callback: function (result) {
        if (result) {
            vm.commentaireLiens ="test";
            $scope.$apply();
        } 
    }
})

AngularJS modifies the normal JavaScript flow by providing its own event processing loop. This splits the JavaScript into classical and AngularJS execution context. Only operations which are applied in the AngularJS execution context will benefit from AngularJS data-binding, exception handling, property watching, etc... You can also use $apply() to enter the AngularJS execution context from JavaScript.

Keep in mind that in most places (controllers, services) $apply has already been called for you by the directive which is handling the event. An explicit call to $apply is needed only when implementing custom event callbacks, or when working with third-party library callbacks.

For more information, see

Upvotes: 1

Related Questions