Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use ng-include without web server?

Tags:

angularjs

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

like image 360
Hao Avatar asked Jan 20 '13 00:01

Hao


People also ask

Does angular app need a Web server?

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.

Does Angular JS need a server?

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.

How does ng include work?

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.

What is Ng in Web?

ng is the Internet country code top-level domain (ccTLD) for Nigeria.


1 Answers

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.

like image 101
Mark Rajcok Avatar answered Oct 06 '22 00:10

Mark Rajcok