我有一个非常简化的版本,我正在做的事情可以解决问题.
我有一个简单的directive.每当您单击一个元素时,它会添加另一个元素.但是,需要首先编译它才能正确呈现它.
我的研究引导我$compile.但是所有的例子都使用了一个复杂的结构,我真的不知道如何在这里应用.
小提琴在这里:http://jsfiddle.net/paulocoelho/fBjbP/1/
JS就在这里:
var module = angular.module('testApp', [])
.directive('test', function () {
return {
restrict: 'E',
template: '<p>{{text}}</p>',
scope: {
text: '@text'
},
link:function(scope,element){
$( element ).click(function(){
// TODO: This does not do what it's supposed to :(
$(this).parent().append("<test text='n'></test>");
});
}
};
});
Run Code Online (Sandbox Code Playgroud)
Josh David Miller的解决方案:http: //jsfiddle.net/paulocoelho/fBjbP/2/