-1

I have a independent modal in a separate file and it's controller in a separate file and the modal is being included in index.html using data-ng-include. But the $scope variable inside the modal controller are not getting refreshed with the data provided in the input field present inside the modal.

I have tried to declare the same in main.js but it didn't worked.

Thanks in advance

georgeawg
  • 48,608
  • 13
  • 72
  • 95
  • 1
    It is hard to help with a question about code "didn't worked" when the question does not include any of the buggy code. – georgeawg Jun 20 '19 at 22:45
  • 1
    We need more details in order to be able to help – Pytth Jun 20 '19 at 23:05
  • Share your code and what have you tried so far to help you better. – rahim.nagori Jun 21 '19 at 06:28
  • New AngularJS developers often do not realize that `ng-repeat`, `ng-switch`, `ng-view`, `ng-include` and `ng-if` all create new child scopes, so the problem often shows up when these directives are involved. – georgeawg Jun 28 '19 at 16:09

1 Answers1

0

Issues like this can often be because your scope isn't matching the scope of your modal controller. An example of where this can occur is using ng-if around your input as this creates a new child scope.

A quick fix to this may be to add the prefix $parent. your input's ng-model to instead use the scope's parent scope. However a better more reliable fix would be name the controller's instance variable which you can read more about here: https://johnpapa.net/angularjss-controller-as-and-the-vm-variable/ and here: AngularJS ng-if and scopes

OliB
  • 104
  • 1
  • 5
  • The use of `$parent` is a [code smell](https://en.wikipedia.org/wiki/Code_smell), a symptom of a deeper problem. `$parent` is not a robust solution. – georgeawg Jun 28 '19 at 16:01