Bypass file:// restrictions

51 views
Skip to first unread message

Jaco De Villiers

unread,
Jul 11, 2015, 2:36:42 AM7/11/15
to ang...@googlegroups.com
Is there is way to mimic the angular structures in a single file?  I need to ship small web sites that can work offline on a computer.  I know that I can host some sort of web server and have that serve up the small website, but would prefer to still point to file://<<path>\index.html in stead.  

Pointing to the file source prevents angular from loading views / templates / etc because of some browser restrictions.  I want to use grun / gulp to package the angular web site into a single file (JavaScript, CSS excluded) into a single file but still have the same single page / routing as if the web site was structured correctly.

Any ideas?

Regards
Jaco

Pete Bacon Darwin

unread,
Jul 11, 2015, 4:27:38 PM7/11/15
to ang...@googlegroups.com
You can preload the `$templateCache` using `<script type="ng-template">` or similar inside your HTML file or do it programmatically similar to https://www.npmjs.com/package/ng-html2js

But this won't help with getting data from files.

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Jaco De Villiers

unread,
Jul 12, 2015, 6:30:05 AM7/12/15
to ang...@googlegroups.com
Thanks Pete, I will give it a go.  Data loads fine, processedData.js contains the data and is loaded with a normal script tag.  I just have issues where angular try and load views / templates etc on demand.  And then same origin / file:// policies in the browsers block the http requests

--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/GEai2j2pCMI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.

Sander Elias

unread,
Jul 12, 2015, 8:53:43 AM7/12/15
to ang...@googlegroups.com
Hi Jaco,

If you are using a gulp, have a look at gulp-angular-templatecache. I believer there is also a grunt version.
What this does, is it puts all your template files into a .js file that you can load just as any other JS file. This js file does prefill the $templateCache for you, so you don't have to change anything else.
I prefer this tool over the ng-html tool that Pete referenced, but they are very similair.

Regards
Sander

Jaco De Villiers

unread,
Jul 13, 2015, 3:14:04 AM7/13/15
to ang...@googlegroups.com
Thanks Sander, that sounds like the solution.  It will allow me to develop in a structured site and deploy to single page site with templates as js files.  I will update this post with my progress when I get a chance to play

--

Jaco De Villiers

unread,
Aug 6, 2015, 4:21:25 AM8/6/15
to ang...@googlegroups.com
It worked like a dream!!!!!  I now have gulp building the template and node serving it for testing.  It also works from file:///

Thanks guys
Reply all
Reply to author
Forward
0 new messages