1

Here is a source of the main.html file

<!DOCTYPE html>
<html>
<head>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>

    <script>
        var myApp = angular.module ('myApp',[]);
        myApp.controller('myCtrl', function ($scope){
            $scope.name = "Tim";
            $scope.partialStuff = [ 'a', 'b', 'c' ];
            alert(window.angular.version.full);//1.3.14 is displayed
        });
    </script>
</head>
<body ng-app="myApp">
    <div ng-controller="myCtrl">
            {{name}}
        <div ng-repeat="partialVar in partialStuff">
            Hello: <div ng-include src="'part.html'"></div>
        </div>
    </div>
</body>
</html>

Also there is a part.html that contains a plain text 'part' - just several symbols.

Both files main.html and part.html are located in the same folder.

When I open main.html in the browser, I don't see three repeats of the content from part.html however I see three Hello:. Seems like part.html is not loaded.

Why?

Thank you.

Please place it within the body tag to make it work

<script type="text/ng-template" id="part.html">
  part
</script>
4
  • What's coming up in your network tab, I'm assuming it couldn't load the file? Your app probably has the wrong directory set up. Commented Apr 8, 2015 at 17:06
  • any console errors ? if no errors check the network and see whether the templates are loading correctly Commented Apr 8, 2015 at 17:06
  • Use fiddler to see what the request is doing. Commented Apr 8, 2015 at 17:13
  • Nope, no errors. The file part.html is not loaded. (that's in Google Chrome). FF - works fine. The solution is found (please see my comment below). Thank you! Commented Apr 8, 2015 at 17:18

3 Answers 3

15
<div ng-include="'part.html'"></div>

should be the correct syntax I believe. More info here

EDIT: also, the file path should be from the root and not relative of the html file.

Sign up to request clarification or add additional context in comments.

5 Comments

I don't think there should be a double quote followed by a single quote. Use one or the other.
@Scottie yes there should when url is string
Is the path relative to the root folder and not the html file?
<div ng-include src=... is not supported but operational syntax.
I am having a similar issue when I inspect the code I see <!-- ngInclude: 'features/common/fields/basicFeatureHeader.html' --> <!-- ngInclude: 'features/common/fields/basicFeatureFilter.html' --> <!-- ngInclude: 'features/common/fields/basicFeatureResultsGrid.html' --> but the html is not rendering
5

You cannot import local files directly using the file:// protocol.

You should take a look at: Is it possible to use ng-include without web server?

2 Comments

Actually, you can, but not in every browser. IE and Chrome are the problem ones.
Yes. And I've just checked - it works in FF. The question appeared when worked with a Google Chrome. The solution found here: stackoverflow.com/questions/14420337/…
0

ng-include can be used as:

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

This will surely include your files like a normal src. ng-include work on local server also.There is no need to put extra server like tomcat to run this file. This will run simply like a html file.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.