Suicide Bunny Suicide Bunny - 1 year ago 87
AngularJS Question

ng-include not working for angularJS

I was trying to repeat what was done in angular template at However, something has gone wrong and I couldn't figured out what it is.

It just looks like


<div class="container">
<div class="row row-content" ng-controller="MenuController ">
<div class="col-xs-12">
<ul class="nav nav-tabs" role="tablist">
<li role="presentation"
<a ng-click="select(1)"
aria-controls="all menu"
role="tab">The Menu</a></li>
<li role="presentation"
<a ng-click="select(2)"
<li role="presentation"
<a ng-click="select(3)"
<li role="presentation"
<a ng-click="select(4)"
<div class="tab-content">
<ul class="media-list tab-pane fade in active">
<ul class="media-list">
<li class="media" ng-repeat="dish in dishes | filter:filtText">
<div class="media-left media-middle">
<a href="#">
<img class="media-object img-thumbnail"
ng-src={{dish.image}} alt="Uthappizza">
<div class="media-body">
<h2 class="media-heading">{{}}
<span class="label label-danger">{{dish.label}}</span>
<span class="badge">{{dish.price | currency}}</span></h2>

and index.html

<!DOCTYPE html>
<html lang="en" ng-app="confusionApp">

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head
content must come *after* these tags -->

<title>Ristorante Con Fusion</title>
<!-- Bootstrap -->
<!-- build:css styles/main.css -->
<link href="../bower_components/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="../bower_components/bootstrap/dist/css/bootstrap-theme.min.css" rel="stylesheet">
<link href="../bower_components/font-awesome/css/font-awesome.min.css" rel="stylesheet">
<link href="styles/bootstrap-social.css" rel="stylesheet">
<link href="styles/mystyles.css" rel="stylesheet">
<!-- endbuild -->

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src=""></script>
<script src=""></script>

<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<a class="navbar-brand" href="#/"><img src="images/logo.png" height=30 width=41></a>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#/">
<span class="glyphicon glyphicon-home"
aria-hidden="true"></span> Home</a></li>
<li><a href="#/aboutus">
<span class="glyphicon glyphicon-info-sign"
aria-hidden="true"></span> About</a></li>
<li><a href="#/menu">
<span class="glyphicon glyphicon-list-alt"
<li><a href="#/contactus">
<i class="fa fa-envelope-o"></i> Contact</a></li>

<header class="jumbotron">

<!-- Main component for a primary marketing message or call to action -->

<div class="container">
<div class="row row-header">
<div class="col-xs-12 col-sm-8">
<h1>Ristorante con Fusion</h1>
<p style="padding:40px;"></p>
<p>We take inspiration from the World's best cuisines, and create
a unique fusion experience. Our lipsmacking creations will
tickle your culinary senses!</p>
<div class="col-xs-12 col-sm-2">
<p style="padding:20px;"></p>
<img src="images/logo.png" class="img-responsive">
<div class="col-xs-12 col-sm-2">

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

<footer class="row-footer">
<div class="container">
<div class="row">
<div class="col-xs-5 col-xs-offset-1 col-sm-2 col-sm-offset-1">
<ul class="list-unstyled">
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Menu</a></li>
<li><a href="#">Contact</a></li>
<div class="col-xs-6 col-sm-5">
<h5>Our Address</h5>
121, Clear Water Bay Road<br>
Clear Water Bay, Kowloon<br>
<i class="fa fa-phone"></i>: +852 1234 5678<br>
<i class="fa fa-fax"></i>: +852 8765 4321<br>
<i class="fa fa-envelope"></i>:
<a href=""></a>
<div class="col-xs-12 col-sm-4">
<div class="nav navbar-nav" style="padding: 40px 10px;">
<a class="btn btn-social-icon btn-google-plus" href=""><i class="fa fa-google-plus"></i></a>
<a class="btn btn-social-icon btn-facebook" href=""><i class="fa fa-facebook"></i></a>
<a class="btn btn-social-icon btn-linkedin" href=""><i class="fa fa-linkedin"></i></a>
<a class="btn btn-social-icon btn-twitter" href=""><i class="fa fa-twitter"></i></a>
<a class="btn btn-social-icon btn-youtube" href=""><i class="fa fa-youtube"></i></a>
<a class="btn btn-social-icon" href="mailto:"><i class="fa fa-envelope-o"></i></a>
<div class="col-xs-12">
<p style="padding:10px;"></p>
<p align=center>© Copyright 2015 Ristorante Con Fusion</p>

<!-- build:js scripts/main.js -->
<script src="../bower_components/angular/angular.min.js"></script>
<script src="scripts/app.js"></script>
<script src="scripts/controllers.js"></script>
<script src="scripts/services.js"></script>
<!-- endbuild -->



enter image description here

enter image description here

They are in the same folder. And I am using "''".
Thanks for the help!

Answer Source

I had a similar problem and I solved it by running a simple nodejs server to serve static files - http-server.

The problem is because of file:// protocol. Mostly all browsers disallow XHR requests when file is been served from file://. That is why AJAX requests are failing. And ng-include use them to download files.

You can launch Chrome with --allow-file-access-from-files parameter to disable checks for file://.

FireFox should load files if they are in same folder (check this for more info).

But personally prefer to start simplest NodeJS script to serve files. Make sure you have nodejs installed, then:


$ sudo npm install http-server -g

Then from your project directory:

$ http-server

Now you can access your files from:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download