Angular 2:组件中的函数错误

时间:2017-04-12 14:53:21

标签: angular templates ionic2 static-methods

我有我的组件获取模板的功能。这是:

/**
* Return template from template's cache
*
* @param url_path - way to needed template
*/
export function getTemplate(url_path)
{
  if (window['app_templates'][url_path]){
    return window['app_templates'][url_path];
  }else{
    console.error('Failed to load template by path ' + url_path);
    return "";
  }
}

在组件中我使用此功能:

import { getTemplate } from "../../services/helpertools";


@Component({
  template: getTemplate('pages/tabs/tabs')
})

但是发生错误:

 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

如何解决?

1 个答案:

答案 0 :(得分:0)

返回内容中的问题,而不是您执行此操作的方式。我尝试了同样的方法,但返回像这样的静态内容

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

@Component({
    selector: 'firm-questions',
    template: getTemplate()
})

工作正常。因此,请检查并发布您从此功能获得的内容