【问题标题】:Angular 2: error with function in componentAngular 2:组件中的功能错误
【发布时间】:2017-04-12 23:14:06
【问题描述】:

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

/**
* 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

如何解决?

【问题讨论】:

    标签: angular templates ionic2 static-methods


    【解决方案1】:

    返回内容的问题,而不是您的处理方式。我尝试了同样的方法,但返回这样的静态内容

    export function getTemplate()
    {
        return '<h1>test</h1>';
    }
    
    @Component({
        selector: 'firm-questions',
        template: getTemplate()
    })
    

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

    【讨论】:

    • 没有。原因是我不能使用函数返回模板。请问你知道怎么解决吗?
    • 恐怕不是角度问题。这是一个例子plnkr.co/edit/JBTerWpLxTFlsC8ioow7?p=preview
    • 是的,我愿意。我使用 Ionic 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-b​​rowser”:“ 4.0.1", "@angular/platform-b​​rowser-dynamic": "4.0.1", "@angular/platform-server": "4.0.1",
    • 可能是缓存问题? run 和 run 之间唯一真正的区别——prod 是缓存
    猜你喜欢
    • 2017-04-28
    • 2017-06-12
    • 1970-01-01
    • 1970-01-01
    • 2017-08-04
    • 2018-09-17
    • 1970-01-01
    • 1970-01-01
    • 2020-01-11
    相关资源
    最近更新 更多