与templateUrl角指令 - 问题上Plunker? [英] Angular Directive with templateUrl - Issue on Plunker?
问题描述
我可以链接到一个Plunker中的特定文件?具体来说,我想使用角的templateUrl指令内外部化的指令,我正在创建的HTML:
Can I link to a specific file within a Plunker? Specifically, I'd like to use Angular's "templateUrl" within a directive to externalize the HTML for a directive I'm building:
myApp.directive('groupedlist', function() {
return {
restrict: 'E',
scope: true,
templateUrl: '/groupedList.html',
link: function() {}
};
});
我有一个名为包含HTML模板groupedList.html的文件,但似乎这些都是Plunker项目中的逻辑文件 - 我的浏览器抱怨,因为它无法找到groupedList.html。是否有可能做什么,我尝试使用Plunker办?因为我想外部化的HTML内容的无意义的量我宁可不使用模板属性。
I have a file called "groupedList.html" that contains a HTML template, but it seems like these are logical files within a Plunker project - my browser complains because it can't find groupedList.html. Is it possible to do what I'm trying to do using Plunker? I'd rather not use the "template" attribute because there is a not-insignificant amount of HTML content I'd like to externalize.
推荐答案
templateUrl犯规与绝对URL的工作,使用相对URL,而不是(像'./page.html'或'../templates/page.html')。如果妳需要跨域页面加载到模板,U可以做一个请求(XMLHtt prequest),并设置STRING HTML作为模板。
templateUrl doesnt work with absolute URLs, use relative URL instead (like './page.html' or '../templates/page.html'). If u need to load cross domain page to template, u can do a request (XMLHttpRequest) and set STRING HTML as a template.
这篇关于与templateUrl角指令 - 问题上Plunker?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!