3

I know this is stupid, but I have a situation where I need to include a template through ng-include and another template in ng-view using angular router. But the problem is that both templates have same controller, as the methods in the controller for these two templates are tightly coupled. But when I include the controller through both ng-controller directive and route provider my model is not getting bound to the view. Can anyone please suggest a solution?

Please note that ng-controller directive is in one template and NOT in the div with ng-include directive

  • 1
    it would be nice if you prepare a simple code to start to work on :) – Aᴍɪʀ Dec 25 '15 at 19:25
  • It seems like you are facing scope hierarchy related issue, basically what happening is `ng-include` create a child scope, So if you wrote `ng-controller` on `ng-include ` directive then it won't work as the inner content will have not in your current scope, they will in `ng-include` child scope, The solution would be use `controllerAs` syntax/ just move your `ng-controller` directive to the template itself(this is not good solution).. Or you could create your own directive which will work like the `ng-include` but it would not create a new scope http://stackoverflow.com/a/29115532/2435473 – Pankaj Parkar Dec 25 '15 at 19:30
  • I have not written ng-controller with ng-include ditective. It is in one of the templates itself. But anyways. Thanks! You just provided me a new insight to look into this issue. – user3318968 Dec 26 '15 at 10:32

0 Answers0