Controller cant access ng-model inside Ionic Modal


I have injected a modal by angular’s script loading technique inside a view that has one controller . Now I have a model inside this modal . But I am not able to access this model inside the controller of the whole view . Is it mandatory that I should specify a seperate controller for the modal . Please help .???


No, you don’t NEED a new controller for the modal. If you create the modal like this :

 $ionicModal.fromTemplateUrl('modal.html', function(modal) {
  }, {
    // Use our scope for the scope of the modal to keep it simple
    scope: $scope,
    // The animation we want to use for the modal entrance
    animation: 'slide-in-up'

you will have access to the $scope in the modal.


Yea that is supposed to work that way , but for me I have a ng-click and a ng-model under the same controller . THe ng-click works but the cant access the model from that controller . When I specify a seperate controller for the modal , it works as expected , But I dont think thats required . Its just complicating things … Thanks in advance …


Are you using “dot notation” on your main controller (the one that instantiates the modal)?


Yea I am doing it that way .


Does that affect the availabality of scope under the controller . Please Help !!!


Without dot notation (objects vs. primiitives), you will often struggle with Angular due to directives that have their own child scopes or isolate scopes. Always use dot notation is a good rule of thumb.

To be more help, we’ll really need a CodePen sample. Try forking on like this and put your code in it.

Be sure to change the Ionic includes to whatever version you are using.


I am basically having a angular datepicker inside the modal . I tried specifying model as


but when I try to access the value from the controller I cant do it . Is’nt $ supposed to have the value .


Haaaa… Finally got it right . I was supposed to initialize the model like


That worked. Thank you …!!!