Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.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
Angular 角度2:组件中的功能错误_Angular_Templates_Ionic2_Static Methods - Fatal编程技术网

Angular 角度2:组件中的功能错误

Angular 角度2:组件中的功能错误,angular,templates,ionic2,static-methods,Angular,Templates,Ionic2,Static Methods,我有一个函数,它是为我的组件获取模板。这是: /** *从模板的缓存中返回模板 * *@param url_path-指向所需模板的路径 */ 导出函数getTemplate(url\u路径) { 如果(窗口['app_templates'][url_path]){ 返回窗口['app_templates'][url_path]; }否则{ console.error('未能通过路径'+url\u路径加载模板); 返回“”; } } 在组件中,我使用此功能: 从“../../services/

我有一个函数,它是为我的组件获取模板。这是:

/**
*从模板的缓存中返回模板
*
*@param url_path-指向所需模板的路径
*/
导出函数getTemplate(url\u路径)
{
如果(窗口['app_templates'][url_path]){
返回窗口['app_templates'][url_path];
}否则{
console.error('未能通过路径'+url\u路径加载模板);
返回“”;
}
}
在组件中,我使用此功能:

从“../../services/helpertools”导入{getTemplate}”;
@组成部分({
模板:getTemplate('页面/选项卡/选项卡')
})
但是发生了一个错误:

 Error: Error encountered resolving symbol values statically. Calling
 function 'getTemplate', function calls
            are not supported. Consider replacing the function or lambda with a
reference to an exported function,
            resolving symbol TabsPage in
            D:/denwerready/-readyscript/modules/mobilesiteapp/appsource/src/page
s/tabs/tabspage.ts, resolving symbol
            TabsPage in D:/denwerready/-readyscript/modules/mobilesiteapp/appsou
rce/src/pages/tabs/tabspage.ts
Error: Error encountered resolving symbol values statically. Calling function 'g
etTemplate', function calls are not supported. Consider replacing the function o
r lambda with a reference to an exported function, resolving symbol TabsPage in

如何解决它?

返回内容中的问题,而不是以您的方式。我尝试了同样的方法,但返回静态内容如下

export function getTemplate()
{
    return '<h1>test</h1>';
}

@Component({
    selector: 'firm-questions',
    template: getTemplate()
})
导出函数getTemplate()
{
返回“测试”;
}
@组成部分({
选择器:“坚定的问题”,
模板:getTemplate()
})

它很好用。所以,请检查并发布您从该功能获得的内容

否。原因是我无法使用该功能返回模板。也许你知道怎么解决这个问题?恐怕不是关于角度的问题。这里有一个例子是的,我知道。我使用离子2应用程序。当我使用命令“ionic run android”时。这一切都很好,但当我使用命令“ionic run android--prod”时。它试图编译用于生产,当出现错误时。我使用“@angular/common”:“4.0.1”、“@angular/compiler”:“4.0.1”、“@angular/compiler cli”:“4.0.1”、“@angular/core”:“4.0.1”、“@angular/forms”:“4.0.1”、“@angular/http”:“4.0.1”、“@angular/platform browser”:“4.0.1”,“@angular/platform server”:“4.0.1”,可能是缓存问题?run和run-prod之间唯一的真正区别是缓存