Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/470.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.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包含来自另一个页面的模板_Javascript_Html_Angularjs_Templates_Angularjs Ng Include - Fatal编程技术网

Javascript Angularjs包含来自另一个页面的模板

Javascript Angularjs包含来自另一个页面的模板,javascript,html,angularjs,templates,angularjs-ng-include,Javascript,Html,Angularjs,Templates,Angularjs Ng Include,我在html页面中有一个模板要包含在另一个页面中。这是因为这两个html非常长,我不能只使用一个页面来同时使用这两个页面。所以我决定把它们分开。这是我的情况: 在partials/template.html中 <script type="text/ng-template" id="myTemplate"> myTemplate.. </script> 我的模板。。 在partials/my_layout.html中 <ng-include src="'

我在html页面中有一个模板要包含在另一个页面中。这是因为这两个html非常长,我不能只使用一个页面来同时使用这两个页面。所以我决定把它们分开。这是我的情况:

在partials/template.html中

<script type="text/ng-template" id="myTemplate">
    myTemplate..
</script>

我的模板。。
在partials/my_layout.html中

<ng-include src="'./partials/template.html'"></div>


但现在不行了。加载页面时没有显示任何内容。如何访问
template.html
页面的模板?

这可能是一个相对路径问题。路径应该是从index.html到模板的路径,而不是从一个模板到另一个模板的路径。试着这样做:

编辑

我刚刚注意到这是一个脚本模板。您为模板提供的id是可以在ng include的src中访问它的密钥。试试这个:


是的,但它在另一个html文件中。这样,它就无法识别模板的id。。如果myTemplate在ng inlcude的同一页中,那么是的,它起作用了。但是通过这种方式nopeOk,尝试将模板http拖出到一个单独的文件中(周围没有脚本标记)。然后,在需要使用该文件的两个位置都包含该文件的路径