0

So im making a project for my self.

Right now, im having a simple index.html page, with some design, and it gets some info from an API, and display it with angular. This works just fine.

But i have another dir(folder) called follow that contains another .html file, with some animated html(JQuery UI), that i want to show on the index.html file in the root. Not just the code, but as preview, like normal html pages. How is this possible?

I've tried using the ng-include, on a div, but doesnt work. I've tried JQuery's .load() function, but that complains about cross-domain even when its all local.

Here's come of the things i've tried:

<div ng-include="'notify/followers-notification.html'"></div>
...
<div id="teest"></div>
...
$( "#teest" ).load( "notify/followers-notification.html" );
...

Edit
This is what im getting in the console, from JQuery: enter image description here

Devjosh
  • 6,450
  • 4
  • 39
  • 61
Patrick R
  • 1,949
  • 3
  • 32
  • 58
  • Are there any errors in the console, what is not working? Is the page not loaded? – blacksheep_2011 Jul 20 '16 at 12:20
  • @blacksheep_2011 i've updated the post, with some info, right now angular is having some trouble for some reason. Im gonna try debug it, and see if i can get something out for you. – Patrick R Jul 20 '16 at 12:23

2 Answers2

1

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. An easy fix around this is to use http-server to serve your contents over a local server.

If you don't want to use server then one workaround is to inline your templates:

<script type="text/ng-template" id="sample.html">
  <div>This is my sample template</div>
</script>

<div ng-include src="'sample.html'"></div>

This puts your template into Angular's template cache. When an ng-include directive is processed, Angular checks the cache first.

Vivek Sharma
  • 164
  • 1
  • 8
  • I've been thinking on a server, and using nodejs, but no. I want it to run local, without a server or anything, just call a API, and CDN for css and js etc.. and just have it all in "one file".. And it must be possible to be able to include the second html file, into the index, and see the angular js like in the index file.. hope that made sense – Patrick R Jul 20 '16 at 12:33
0

It's because browsers (Chrome at least) don't allow AJAX requests on local environment, you need some kind of server, or to run chrome with --allow-file-access-from-files flag.

How to launch html using Chrome at "--allow-file-access-from-files" mode?

Community
  • 1
  • 1
tomek550
  • 470
  • 4
  • 15