When it comes to integrating HTML partials into your code, the ng-include
directive is a useful tool. There are multiple ways in which you can combine it with the ng-controller
directive:
One option is to nest an element with ng-include
inside an ng-controller
:
<div ng-controller="testCtrl">
<div ng-include="'view.html'"></div>
</div>
Alternatively, you can include an ng-controller
directive within an included partial:
<!-- index.html -->
<div ng-include="'view.html'"></div>
<!-- view.html -->
<div ng-controller="testCtrl">
<p>{{ helloworld }}</p>
</div>
You can also use both ng-include
and ng-controller
directives on the same element:
<div ng-controller="testCtrl" ng-include="'view.html'"></div>
It's important to note that the string literal in the ng-include
directive should be enclosed in single quotes, as it expects an expression.
Depending on your specific needs, you may have to utilize one or more of these techniques. Additionally, working with directives (such as the UI Bootstrap modal) that have their own controllers might be necessary.
I've created a Plunker example here showcasing some functional uses of the ng-include
options mentioned above, including dynamically swapping included templates.
While I can't guarantee the practicality of using this approach for a production application, it does seem feasible based on initial observation.