javascript - 可以使用这个 angularJS html 属性 : ng-include ="{{...}}"?

标签 javascript html angularjs

我正在做一个应该在网页中加载帖子的小项目。我认为我可以使用 Angular ng-repeat 来快速创建帖子,然后使用 ng-include 加载帖子格式的内容,这是一个小的 HTML 页面。这是代码:

<section ng-controller="PostController as posts" ng-show="!$first">
    <div ng-repeat="post in posts.info">
        <h2>{{post.title}}</h2>
        <div ng-include="posts/{{post.content}}"></div> //here is the problem
        <span class="date">{{post.createdOn}}</span>
        <span class="author">{{post.author}}</span>
    </div>
</section>

我从 JSON 中导入标题、日期和作者的内容,并且它有效。 当我加载页面时,我看到应该加载的 html 页面丢失了。我会将帖子的正文存储在一个名为“posts”的文件夹中,在这个文件夹中,会有帖子。 所以我查看了问题的渲染页面,我看到 AngularJS 似乎在评论无法加载的内容:我实际上看到了 <!-- ngInclude: '{{post.content}}' --> .

所以我的问题是:如何告诉 AngularJS 从 HTML 标签属性中读取 {{ }} 的结果?

最佳答案

这是一个 Plunker demonstrates这是如何工作的。结果是您不需要 {{}}。只需在双引号中指定 Angular 表达式,如下所示:

<div ng-include="post.content"></div>

关于javascript - 可以使用这个 angularJS html 属性 : ng-include ="{{...}}"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25243050/

相关文章:

javascript - 谁能告诉我如何在按下鼠标并继续直到它在 p5.js 中被释放时触发一个函数

javascript - 如何使用 Javascript 检查脚本是否可以加载

javascript - react : Give back the child new inserted element to parent for update the state

html - 如何使用 CSS3 在分页上单击时更改链接的颜色

javascript - 如何使用 ramda 库合并两个数组?

javascript - 将 onclick 处理程序添加到超链接标记以触发 ajax?

java - 正则表达式 "either a semicolon or the end of the string"

unit-testing - 使用依赖项测试 AngularJS 服务

angularjs - UI-GRID 的默认标题单元格模板是什么?

android - AngularJS HTTP 状态 -1