I'm running an AngularJS app which merely include a file
<div ng-include src="'sample.html'"></div>
That works when run under web server. But if the web app is run from merely double clicking from file explorer (i.e. not from web server), it doesn't include the file
Does ng-include works outside of web server? I checked the Network status on Chrome, it says OPTIONS on Method, and Load cancelled on Status
You don't need a server-side engine to dynamically compose application pages because Angular does that on the client-side. If the application uses the Angular router, you must configure the server to return the application's host page ( index.html ) when asked for a file that it does not have.
Angular Js doesn't require a server until you want to use angular directives like 'ng-include', or you want page routing or ajax request in your application.
The ng-include directive includes HTML from an external file. The included content will be included as childnodes of the specified element. The value of the ng-include attribute can also be an expression, returning a filename. By default, the included file must be located on the same domain as the document.
ng is the Internet country code top-level domain (ccTLD) for Nigeria.
One workaround is to inline your templates:
<script type="text/ng-template" id="sample.html">
<div>This is my sample template</div>
</script>
Fiddle.
This puts your template into Angular's template cache. When an ng-include directive is processed, Angular checks the cache first.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With