Search code examples
angularjsjquery-chosenangular-strap

Post-load event Angularstrap modal


I'm using angular chosen with angularstrap and i'm having problems with the initial value of the selector to be selected. The way i got it to work is i set a Timeout on the model attached to the selector to wait for the dom and then set the model value. So my guess is that chosen needs to wait for the dom to be created before it can initialize the selected option.

$scope.showModal = function() {
    myModal.$promise.then(myModal.show);

    // hack to make chosen load 
    $timeout(function () { 
            myModal.$scope.SelectedColor = "green";
    }, 500 );
};

in my opinion this timeout solution is not a good one and i would like to find a better way to set the model after the dom has been created.


Solution

  • This is because chosen directive is calling trigger("chosen:updated") before the DOM is actually loaded. A fix would be adding $timeout() to the $watchCollection trigger.

    This has been discussed and looks like the solution is here in the answer from kirliam.

    Someone should issue a pull request for this issue.

    edit: I issued a pull request for a fix regarding this issue. Hope it gets merged in.