2016-11-09 20 views
-1

在Angular2應用程序中,我想使用ajax從後端檢索html標記字符串,並將其用作Angular2中的模板。如何使用從後端檢索的字符串作爲Angular2中的模板?

// The str I get from server by ajax is: 
var str = "<my-hero [hero]=\"hero\"></my-hero>" 

當應用程序已在瀏覽器中運行時。如果我$('myHeroParent')。append(str)。此代碼不起作用。

您如何完成這項工作?它被稱爲動態加載組件嗎?

回答

-1

我認爲你可以在組件發送這個特殊的HTML作爲模板,這樣

angular.module('MenuApp') 
.component('itemset1', { 
templateUrl: '<my-hero [hero]=\"hero\"></my-hero>', 
}); 
相關問題