【问题标题】:angular ng-include not working角度 ng-include 不起作用
【发布时间】:2016-11-24 03:56:12
【问题描述】:

这是我的 html 的一部分,我试图在其中包含另一个 HTML 文件“content.html”,但它不起作用。源中的那些地址是正确的,但我仍然无法实现。

  <!DOCTYPE html>
  <html lang="en">
  <head>

   <!-- Basic Page Needs
  –––––––––––––––––––––––––––––––––––––––––––––––––– -->
  <meta charset="utf-8">
  <title>Your page title here :)</title>
  <meta name="description" content="">
  <meta name="author" content="">
 <!-- Scripts
 –––––––––––––––––––––––––––––––––––––––––––––––––– -->
 <script type="text/javascript" src="js\jquery-3.0.0.min.js"></script>
 <script type="text/javascript" src="js/angular.min.js"></script>
  </head>
  <body>
  <div ng-include src="'content.html'"></div>
  </body>
  </html>

这是我的 content.html

  <div class="container">
  <h1>Heading!</h1>
  </div>

【问题讨论】:

    标签: javascript html angularjs angularjs-ng-include


    【解决方案1】:

    您应该将ng-app="" 添加到您的页面html 标记中,这样角度就会在页面上启动。之后将开始遍历页面并收集所有指令并编译它们。

    <html lang="en" ng-app="">
    

    您也可以直接在ng-include 属性中传递模板值,而不是ng-includesrc

    <div ng-include="'content.html'">
    

    Demo Plunkr

    【讨论】:

    • 作为属性使用的时候是不是也需要作为ng-include="'content.html'"使用? src不是只有在使用ng-include作为元素时才有效吗?
    • @Lex 感谢您的提醒,将在答案中添加它作为改进,谢谢:)
    猜你喜欢
    • 2014-08-20
    • 1970-01-01
    • 2015-02-20
    • 1970-01-01
    • 2015-12-22
    • 2016-08-17
    • 2018-03-27
    • 1970-01-01
    相关资源
    最近更新 更多