编程语言
首页 > 编程语言> > javascript – angular ng-include not working

javascript – angular ng-include not working

作者:互联网

这是我的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>

最佳答案:

您应该将ng-app =“”添加到页面html标记中,以便在页面上启动角度.之后将开始遍历页面&将收集所有指令&它会编译它们.

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

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

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

Demo Plunkr

标签:javascript,angularjs,html,angularjs-ng-include
来源: https://codeday.me/bug/20190516/1115196.html