How to make angularjs app work locally without accessing it via http

If you create any anugularjs app and try accessing index.html directly on any browser without having it running on webserver, it will not get rendered properly

The reason being,ng-view and ng-include make ajax requests to serve the template file. Because you’re running it locally, it can’t make that request.
For example making an ajax request to include ‘file://paritals/somefile.html’ will not work as browser won’t allow such access to local file system

An easy workaround for simple app would be to include the partial template file within the index.html only. SOmething like this :

 <div ng-view>
   <script type="text/ng-template" id="home.html">
     Here content of included file will come
   </script>
 </div>

Now such file can be accessed locally

Uday Ogra

Connect with me at http://facebook.com/tendulkarogra and lets have some healthy discussion :)

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *