Using ngInclude multiple times in Angularjs

I have this little script and the controller in angular is completely empty so there is nothing.

My question is, why can't I run ngIncludes (no errors by the way)?

<!DOCTYPE html>
<html ng-app="demo">
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<!-- WARNING: for iOS 7, remove the width=device-width and height=device-height    attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<meta name="msapplication-tap-highlight" content="no" />

<script type="text/javascript" src="bower_components/jquery/dist/jquery.js"></script>
<script type="text/javascript" src="bower_components/angularjs/angular.min.js"></script>
</head>
<body>

<div ng-controller="main">
<ng-include src="'templates/android/header.html'" />
<ng-include src="'templates/android/newsfeed.html'" />
</div>

      

+3


source to share


4 answers


I had the same problem, but in my case, I didn't close the div tag correctly:

<div ng-include="'partials/agendar.html'">
<div ng-include="'partials/atendimento.html'">

      

As I understand it, you are doing this, but using the "ng-include" tag. Try this (works great for me). Make sure your angular is up to date and then only use "ng-include" (no "data -"):



<div ng-include="'partials/agendar.html'"></div>
<div ng-include="'partials/atendimento.html'"></div>

      

Hope it helps.

+2


source


You can start without the src attribute like this:

if you give this type it doesn't display any error messages. ng Enable attribute binding so that it doesn't display any error messages.

<data-ng-include="'templates/android/header.html'" />
<data-ng-include="'templates/android/newsfeed.html'" />

      



The right way:

<div data-ng-include="'templates/android/header.html'"></div>
<div data-ng-include="'templates/android/newsfeed.html'"></div>

      

0


source


I prefer correct HTML and suggest you:

<div data-ng-include="'templates/android/header.html'"></div>
<div data-ng-include="'templates/android/newsfeed.html'"></div>

      

0


source


Actually the question is not so clear to me, but I tried like this and it worked correctly:

 <body ng-controller="MainCtrl">
     <div ng-include src='"file1.html"'></div>
     <div ng-include src='"file2.html"'></div>
  </body>

      

Demo

0


source







All Articles