使用ng在Angularjs中多次包含

时间:2014-08-09 09:48:55

标签: javascript angularjs angularjs-ng-include

我有这个小脚本,角度控制器完全是空的,所以没有。

我的问题是为什么我不能跑到ngIncludes(顺便说一句没有错误)?

<!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>

4 个答案:

答案 0 :(得分:3)

我有同样的问题,但就我而言,我没有正确关闭div标签:

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

正如我看到你那样做,但是你正在使用&#39; ng-include&#39;作为标签。试试这样(对我来说很完美)。确保您的角度已更新,然后仅使用&#39; ng-include&#39; (没有&#39;数据 - &#39;):

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

希望它有所帮助。

答案 1 :(得分:0)

你能不用这样的src属性开始:

如果您提供此类型,则不会显示任何错误消息ngInclude属性绑定,因此它不会显示任何错误消息。

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

正确的方法是:

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

答案 2 :(得分:0)

我更喜欢有效的HTML并建议您:

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

答案 3 :(得分:0)

实际上这个问题对我来说并不是那么清楚,但我尝试过这样做并且它运作正常:

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

Demo