One issue I'm facing is that I have only one ng-app. Does this mean I need to do dependency injection for plugins that may not be used on a particular view? For example, if I include ngTagsInput
, does that mean I have to include it in every view even if it's not necessary? This could potentially lead to unnecessary inclusion of JavaScript files.
I am working on a large MVC .NET application and trying to determine the best approach for importing external plugins.
In our main _Layout template, we have code similar to:
<html ng-app="ourApp">
<head>
<!-- all of our includes are here -->
</head>
<body>
<directive></directive>
<anotherdirective></anotherdirective>
@RenderBody()
</body>
</html>
The RenderBody function inserts views from our MVC routing. A sample view may look like this:
<script src="~/Scripts/HomeAngular.js"></script>
<div ng-controller="HomeCtrl">
<directive3></directive3>
</div>
Application JS file:
var app = angular.module('ourApp', ['ngTagsInput']);
Is there a way to avoid injecting ngTagsInput on every view page, especially when it's not required?