search

Home  >  Q&A  >  body text

angular.js - angular使用ng-include,为什么生成不了html代码

今天在学习angularJS的时候,视频讲到ng-include的用法。
说白了也就是把通用的html代码提取到一个html文件里面再include进去而已。

但是我在index.html引入同一目录下的product-title.html时,却不显示product-title.html里面的内容。

angular版本是1.4.8

index.html:

<h3 ng-include="'product-title.html'"></h3>

product-title.html:

{{product.name}}
<em class="pull-right">{{product.price | currency}}</em>

看调试界面生成的是:

<!-- ngInclude: a.html -->

这么一句话。

怪我咯怪我咯2744 days ago531

reply all(4)I'll reply

  • 给我你的怀抱

    给我你的怀抱2017-05-15 16:59:57

    It’s because the page is not run on the http server.

    reply
    0
  • 怪我咯

    怪我咯2017-05-15 16:59:57

    Is there a problem with the path? Check to see if they are of the same level. product-title.htmlindex.html

    reply
    0
  • 黄舟

    黄舟2017-05-15 16:59:57

    Look in the browser, is the html 404? Confirm the file path~

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-05-15 16:59:57

    The value of ng-include must be a variable, not a file name. Assign the file path to a variable, then ng-include='variable name'

    reply
    0
  • Cancelreply