2017-06-30 51 views
0

我正在編寫一個帶有angular.element(document).find(id).html(code)的html代碼,其中有一個ng-click和ng-change在code var。當它寫入HTML代碼,它應該能夠正常工作,分析生成的HTML代碼:使用angular.element產生ng-click和ng-change不起作用

代碼:

<a style="cursor:pointer" title="Atualizar" ng-click="atualizarHistorico(303456)"><i class="mdi-action-autorenew small"></i></a> 

但是當我點擊該按鈕,不執行功能atualizarHistorico()

我生成這樣的事情:

var return = '<a style="cursor:pointer" title="Atualizar" ng-click="atualizarHistorico(303456)"><i class="mdi-action-autorenew small"></i></a></div>'; 
angular.element(document).find('#' + id).html(return); 

只有在這種情況下是不是活像國王,與ng-clickng-change的html代碼生成angular.element

+0

使用jQuery時它工作嗎? – Jack

回答

2

如果您必須追加HTML,您需要訪問$compile服務。然後編譯HTML,並將其鏈接到具有要執行的功能的示波器:

$scope.atualizarHistorico = function(... 

var return = // HTML 
var compiledAndLinked = $compile(return)($scope); 
angular.element(document).find('#' + id).html(compiledAndLinked);