-1

I have function which is gets template for my component. Here it is:

/**
* 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 "";
  }
}

And in component I use this function:

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


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

But occurs a error:

 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

How to solve it?

1 Answer 1

0

The problem in returned content, not in the way you do it. I tried the same way, but return static content like this

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

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

It works fine. So, please check and post content you are getting from this function

Sign up to request clarification or add additional context in comments.

6 Comments

No. The reason is in that I can't use function to return template. May be you know how to solve it?
I'm afraid it's not about angular problem. Here is an example plnkr.co/edit/JBTerWpLxTFlsC8ioow7?p=preview
Yes I do. I use Ionic 2 app. And when I use command 'ionic run android'. All works fine, but when I use command 'ionic run android --prod'. It's try to compile for production, and when gets a error.
I use "@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-browser-dynamic": "4.0.1", "@angular/platform-server": "4.0.1",
maybe it's cache problem? The only real difference between run and run -- prod is cache
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.