有时候,页面中的dom是需要动态生成的,所以这时候就可能需要我们手动去编译动态添加的dom,如下:
/**
* 手动编译动态添加的dom
*/
indexMod.directive('bindHtmlCompile',['$compile',function($compile){
return {
restrict: 'EA',
link: function(scope,element){
scope.$watch(function(){
return angular.element($("#container")).html();
},function(value){
element.html(value);
$compile(element.contents())(scope);
});
}
};
}]);
使用的时候,这样使用:
//html里边使用
<div bind-html-compile id="container"></div>