Search code examples
angularjsangularjs-directiveangularjs-scopeangularjs-ng-repeatng-dialog

why checkbox gets unchecked when i close ngdialog popup after checking it?


when i close the ngdialog popup after checking the checkbox which is inside of it, and again if i open it then the checkbox is getting unchecked, why is it happening do anybody know that? this is my script tag

    <script type="text/ng-template" id="templateId">

    <div id="target" ng-click="test()" ng-controller="tt">
      Click here
      <input type='checkbox' placeholder=''>
    </div>
</script>

this is my example jsfiddle http://jsfiddle.net/mb6o4yd1/264/


Solution

  • It seems that this ngDialog module destroys the controller after it is closed. If you want to access and keep the changes in your controller. Use $parent from your controller.

    I've created this fiddle for you.

    <script type="text/ng-template" id="templateId">
      <div id="target" ng-click="test()">
        Click here
      <input type='checkbox' ng-model="$parent.checkbox">
    </div>
    

    OR

    Using your approach you have to save the values into a factory before leaving the dialog

    Hope it helps.