我要動態添加HTML內容與angularJs
,但得到和錯誤:如何動態地添加HTML內容與AngularJs
"$compile is not defined"
什麼能是什麼原因?
代碼
<td ng-repeat="user in users[0].yds" data-title="'Timeline'" sortable="timeline" style="text-align: center" >
<div class="circle_dynamic"></div>
</td>
angular.module('elnApp')
.controller('ProgramtableCtrl', function ($scope, $location, $filter, ngTableParams,
programTableService) {
for(var i=0; i<=$scope.users[0].projects.length; i++){
for(var j=0; j<$scope.users[0].projects[i].results.length; j++){
if($scope.users[0].projects[i].results[j] == 0){
$(".circle_dynamic").html(
$compile(
""
)(scope)
);
console.log('rm')
}else{
$(".circle_dynamic").html(
$compile(
"<i ng-class='circle_class' style='position: absolute;'></i>"
)(scope)
);
console.log('add')
}
}
}
}, true);
}});
如何動態地添加HTML內容?請幫忙
這是什麼代碼?在指令中?在控制器?向我們展示如何初始化它。 – package
這是在控制器 – user2680731
爲什麼你需要調用$ compile?即使你這樣做,你也應該在指令中做,而不是在控制器中。 – 0xc0de