Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 可以使用此angularJS html属性:ng include=";{{…}";?_Javascript_Html_Angularjs - Fatal编程技术网

Javascript 可以使用此angularJS html属性:ng include=";{{…}";?

Javascript 可以使用此angularJS html属性:ng include=";{{…}";?,javascript,html,angularjs,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}}&

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

{{post.title}
//问题就在这里
{{post.createdOn}}
{{post.author}}
我从一个JSON导入标题、日期和作者的内容,它可以正常工作。 当我加载页面时,我看到应该加载的html页面丢失了。我将把帖子的主要文本存储在一个名为“posts”的文件夹中,在这个文件夹中,会有帖子。 因此,我查看了该问题的呈现页面,发现AngularJS似乎在评论无法加载的内容:事实上,我看到了


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

经过很长时间,我解决了我的问题! 我发现,如果我编写以下代码,它就可以工作:

  <div ng-include="'posts/testPost.html'" class="ng-binding"></div>


不要问我这背后的理论部分,因为我还没有完全理解它是如何工作的。

过了很长时间,我解决了我的问题! 我发现,如果我编写以下代码,它就可以工作:

  <div ng-include="'posts/testPost.html'" class="ng-binding"></div>

不要问我这背后的理论部分,因为我还没有完全理解它是如何工作的。

这是一个如何工作的例子。结果是你不需要{{}。只需使用双引号指定角度表达式,如下所示:

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

这里有一个例子可以说明这是如何工作的。结果是你不需要{{}。只需使用双引号指定角度表达式,如下所示:

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

这项工作:

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

这项工作:

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


这不起作用,浏览器说它找不到URL(而且它没有将
{{post.content}}
作为链接,而是作为
%7B&7post.content%7D%7D
。无论如何,感谢您告诉
“…”
错误!如果您使用ng include,我认为它会在网站上显示所有包含的文件或显示任何错误,我认为这是不可能的…正确的html绑定方式朋友…您尝试过使用ng绑定html吗?这会将html内容绑定到您的div,也许这比包含各种html文件更好你的“post.content”变量?我必须检查它是否有效…现在它得到了URL,但我必须对它进行清理。感谢@Fedaykin告诉我关于ng bind html!这不起作用,浏览器说它找不到URL(而且它没有得到
{post.content})
作为链接,但作为
%7B&7post.content%7D%7D
。无论如何,感谢您告诉
“…”
错误!如果您使用ng include,我认为它会在网站上显示所有包含的文件或显示任何错误,我认为这是不可能的…正确的html绑定方式朋友…您尝试过使用ng绑定html吗?这会将html内容绑定到您的div,也许这比包含各种html文件更好对于“post.content”变量?我必须检查它是否有效…现在它得到了URL,但我必须对其进行清理。感谢@Fedaykin告诉我有关ng bind html!那么,您一开始就不需要动态
ng include
?那么,您一开始就不需要动态
ng include