Q:

When ng-if are trigerd?

I am currently working on functionality for buttons that are opening directive in modal windows, and I wanted to created it simple is possible, so i took modal container and flag it with versus directive:
<div ng-if="vm.Modal.Modal1">
<directive-for-modal-one params="vm.params1"><directive-for-modal-one>
</div>
 <div ng-if="vm.Modal.Modal2">
<directive-for-modal-two params="vm.params2"><directive-for-modal-two>
</div>
....

And in controller there is a function that change activity of all of this modal, vm.Modal.n
function test(name){
        CloseModal();

        vm.Modals[name]= true

    }
function CloseModal() {

        for (var property in vm.Modals) {

            vm.Modals[property]= false;

            }
    }

And problem is in that if you click to open same modal two time, when even the value for ng-if are false and after that true, modal that is reopen are old one, wasn't destroyed. I understand that this is happening because javascript is single thread and that while it is function it will not close, how can I make angular check when this value is changed while I am still inside a function. some kinde refresh or chack command?

A:

I did this with using of $timeoutm.
    CloseModal();

$timeout(function(){
    vm.Modals[name]= true
})

There is explanation and comperation $timeout vs $evalAsync:
AngularJS : $evalAsync vs $timeout

