Sunday, October 7, 2012

AngularJS "ng-include" Gotcha with Controllers

I had a page with many forms in an accordion style grouping, so I decided to have the individual forms in separate HTML documents which are pulled together using "ng-include". All these forms, however, were using the same Controller declared in the parent document.

This turned out to be problematic, as I was finding that the controller's scope variables were not being updated. After much troubleshooting, it seems that every HTML fragment needs its own controller. I'm still not exactly sure why but this seems to be the only way to make things work.

No comments:

Post a Comment