0
我有一个指令可以在其中包含一些HTML。我怎么才能得到它?我已经尝试链接和编译,但我正在获取模板中定义的HTML。这是我的观点:在指令声明中获取HTML
<my-directive ng-model="ctrl.SomeField">
<p> This is the HTML I want! <p>
</my-directive>
这里是我的指令:
return {
restrict: 'E',
scope: {
ngModel: "="
},
template: "<p>This is the HTML that is being returned from compile and link!</p>" +
"<p>This is not the HTML that I want!</p>"
link: {
pre: function preLink(scope, element, attrs) {
var html = element.html(); //returns the html in the directive template
},
post: function postLink(scope, element, attrs) {
var html = element.html(); //returns the html in the directive template
}
},
compile: function(element, attrs){
var html = element.html(); //returns the html in the directive template
}
}
我如何从我的观点得到了HTML而不是从我的指令模板?
编辑:下面是一个例子 - http://plnkr.co/edit/z6gFOrGG01jKoKwISHcW?p=preview
试图用等的console.log(element.find( 'P'));在链接块 – Whisher 2014-11-20 19:56:24
不起作用,仍然返回我不想要的HTML。 – gwin003 2014-11-20 20:11:29
https://gist.github.com/whisher/3733e1f67e63c798952a它的工作原理console.log打印这是我想要的HTML! – Whisher 2014-11-20 20:20:21