2016-05-06 21 views
0

我正在考慮使用非角度傳輸來異步加載模板(實際上,如果模板是字符串或來自請求的承諾,我想要確定構建時間),就像在Angular 2中作爲模板請求承諾

@Component({ 
    directives: [], 
    selector: 'some', 
    template: System.import('./some-template!text') 
}) 
export class SomeComponent {} 

承諾(來自請求)是否可以作爲組件模板提供?

指令/組件是否有某種templateProvider功能?

+0

你是否在談論'templateUrl'的相對路徑? –

+0

@PardeepJain我正在考慮更換templateUrl,因爲我想確定模板是否在編譯時同步加載(使用'require')或異步加載(使用'System.import')。 – estus

回答

1

模板的類型是字符串,see source

或者您可以使用

templateUrl: 'relative/path/from/index.html/some-template.html' 

我試圖做不可能的事與IIFESystem.importno luck.

您可以IIFE嘗試自己的模塊加載器加載templatessynchronouslyasynchronously我不認爲會工作。

See this,爲什麼你必須使用IIFE

+0

感謝您的指向ComponentMetadataFactory的鏈接,我自己並沒有找到它。至於IIFE,它不應該在這裏,因爲System.import返回一個承諾,而不是一個函數。 – estus

+0

不客氣......我明白了,我的壞,從未使用過'System.import' –