2016-05-25 25 views
0
<div id="divProductItems"></div> 

上面的div將被一些html + angularjs元素填充,後面是來自單獨的js文件的ajax調用。但是,angularjs代碼目前無法正常工作。我怎樣才能解決這個問題如何編譯包含Angularjs的動態html代碼?

function getProductItems() { 
    var productSelected = $('#hdnSelectedProducts').val(); 
    callActionWithJson("/Item/ProductItem", function (data) { 
     $("#divProductItems").html(data); // here I add the dynamic code to the above div and (data) contains the dynamic html + angularjs directives 
     filterProductItem(); 
    }, null, "pricingLevelId", $("#ddlPricingLevel").val(), "searchItem", $("#txtSearchItem").val(), "productId", (productSelected.length != null ? productSelected : 0)); 
} 
+0

使用'$編譯()'編譯動態角碼 –

+0

我看到,在一個類似類型的問題,請告訴我,在細節我不能與修復。如何使用$ compile()? –

回答

0

需要在你的控制器注入$compile

$compile($('#divProductItems'))($scope); 
+0

它只是我需要把這個在我的控制器? –

+0

AFAIK你必須寫一個指令 –

+0

是的。如果您在DOM更新後將其放入控制器,它應該可以工作。 –