我正在做一个应该在网页中加载帖子的小项目。我认为我可以使用 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/