AngularJS NG-包括: [英] AngularJS ng-include

查看:188
本文介绍了AngularJS NG-包括:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想包括 NG-重复内的HTML片段,但我可以得到包括不工作。这似乎当前语法NG-包括是比它是previously不同:我看到用很多例子&LT; D​​IV NG-包括SRC =路径/ file.html&GT;&LT; / DIV&GT; 但在的官方文档,它说,使用&LT; D​​IV NG-包括=路径/ file.html&GT;&LT; / DIV&GT; 但随后< A HREF =htt​​p://docs.angularjs.org/api/ng.directive:ngInclude#Example>下来它显示为&LT的页面; DIV NG-包括SRC = 路径/ file.html&GT;&LT; / DIV&GT;

I'm trying to include an html snippet inside of an ng-repeat, but I can't get the include to work. It seems the current syntax of ng-include is different than what it was previously: I see many examples using <div ng-include src="path/file.html"></div> but in the official docs, it says to use <div ng-include="path/file.html"></div> but then down the page it is shown as <div ng-include src="path/file.html"></div>.

Regardles,我试过

Regardles, I tried

&LT; D​​IV NG-包括=意见/ sidepanel.html&GT;&LT; / DIV&GT;

&LT; D​​IV NG-包括SRC =意见/ sidepanel.html&GT;&LT; / DIV&GT;

&LT; NG-包括SRC =意见/ sidepanel.html&GT;&LT; / NG-包括&GT;

&LT; NG-包括=意见/ sidepanel.html&GT;&LT; / NG-包括&GT;

&LT; NG:包括SRC =意见/ sidepanel.html&GT;&LT; / NG:包括&GT;

我的片段是不是很code,但它有很多事情;我在阅读#12361680 的是,可能会导致一个问题,所以我换成侧面板的内容。 HTML 只字,仍然一无所获。

My snippet is not very much code, but it's got a lot going on; I read in SO#12361680 that that could cause a problem, so I replaced the content of sidepanel.html with just the word foo, and still nothing.

我也试过直接在页面声明模板是这样的:

I also tried declaring the template directly in the page like this:

<script type="text/ng-template" id="tmpl">
    foo
</script>

和运行直通的所有变NG-包括引用脚本的 ID ,仍然没什么。

And running thru all the variations of ng-include referencing the script's id, and still nothin'.

我的页面有很多更在里面,但现在我已经剥离下来到眼前这个:

My page had a lot more in it, but now I've stripped it down to just this:

<!-- index.html -->
<html>
<head>
<!-- angular includes -->
</head>
<body ng-view="views/main.html"> <!-- view is actually set in the router -->
    <!-- views/main.html -->
    <header>
        <h2>Blah</h2>
    </header>
    <article id="sidepanel">
        <section class="panel"> <!-- will have ng-repeat="panel in panels" -->
            <div ng-include src="views/sidepanel.html"></div>
        </section>
    </article>
<!-- index.html -->
</body>
</html>

标题渲染,但后来我的模板没有。我得到在控制台或节点没有错误,如果我点击的链接 SRC =意见/ sidepanel.html在开发工具,它带我到我的模板(并显示)。

The header renders, but then my template doesn't. I get no errors in console or from Node, and if I click the link in src="views/sidepanel.html" in dev tools, it takes me to my template (and displays foo).

推荐答案

您必须单引号双引号内的的src 字符串:

You have to single quote your src string inside of the double quotes:

<div ng-include src="'views/sidepanel.html'"></div>

来源

这篇关于AngularJS NG-包括:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆