2014-02-25 33 views
0

當使用$compile(element)(scope)手動將某些數據綁定到dom元素時,我遇到一個奇怪的問題。將模板綁定到數據以在Angularjs中獲取html文本

請檢查example code here.

在這個例子中預覽,當你點擊按鈕「綁定模板」,該模板編制了一些數據和渲染成DOM元素。但是當再次點擊該按鈕時,只顯示該模板。任何想法可能是這裏的問題。

回答

1

我不知道你在做什麼這樣做,但你應該使用指令來代替。

Here is your plunker working with a directive

app.controller('MainCtrl', function ($scope, $http, $templateCache, $compile) { 
     $scope.name = 'World'; 
     $scope.result = '<empty>'; 

     $scope.bindTemplate = function() { 
       $scope.item = { 
        CaseNumber: 1234, 
        CandidateName: 'Joe Smith', 
        CandidateEmail: '[email protected]', 
        IsActive: true 
       } 
     }; 

}); 

app.directive('caseDetails', function() { 
    return { 
     templateUrl: "template.html" 
    } 
}) 
相關問題