【发布时间】:2013-02-23 03:02:32
【问题描述】:
我对我正在做的事情有一个非常精简的版本,可以解决问题。
我有一个简单的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>");
});
}
};
});
Josh David Miller 的解决方案: http://jsfiddle.net/paulocoelho/fBjbP/2/
【问题讨论】:
标签: angularjs angularjs-directive dynamically-generated