2016-09-08 31 views
0

我已經發出POST請求來獲取塊的html。這是帖子:角度指令在POST後消失

$scope.changeMenu = function() { 
     $http({method: "POST", url: "/menu"}).then(function (response) { 
        $scope.selected_menu_item = response.data; 
       }, 
       function() { 
        $scope.selected_menu_item = response.data; 
       }); 
    } 

塊,我在那裏顯示接收到的HTML ::

<div ng-bind-html="selected_menu_item" class="chosen-item"> 

比我得到的迴應: enter image description here

但角度指令已經消失HTML文檔中: enter image description here

在POST之後我需要做些什麼來獲取角度指令?

感謝

+0

您不能在通過'ng-bind-html'插入的HTML內部使用角度指令/綁定。 – Claies

回答

2

ng-bind-html指令並不$編譯傳遞給它的數據,使文本中的指令將不被鏈接到一個範圍或指令處理。 ng-include會編譯你傳遞它的模板的內容,但是因爲你正在使用METHOD發送的$ http請求的響應:'POST'只是使用ng-include在這種情況下不起作用。如果這只是一個get請求,那麼可以使用ng-include而不需要額外的腳本,因爲ng-include將執行http請求。如果這不起作用,讓我知道將發佈代碼自己執行$ compile步驟。

+0

謝謝,它幫助:) – Yaroslav