我有一个可以正常工作的自定义markdown指令。现在我想在通过markdown指令加载的内容中使用自定义的youtube指令。 youtube指令本身工作正常,但只要我把它放在markdown文件中,就会被角度忽略。指令中的指令
下工作正常(但不是我想做的事):
的.html
<div markdown link="contentfile.md">
</div>
<div my-youtube code="'videoidhere'"></div>
.MD
markdown content here
下面就是我想要做的(但不工作):
的.html
<div markdown link="contentfile.md">
</div>
.MD
markdown content here
<div my-youtube code="'videoidhere'"></div>
more markdown content here
在第二种情况下,它似乎如果YouTube指令从未被调用过。
在评估markdown指令之后,我需要做些什么来告诉angular来评估该指令?
为了完整起见,这里的指令:
降价:
app.directive('markdown', function($http) {
var converter = new Showdown.converter();
return {
restrict: 'A',
scope: { link: '@' },
link: function (scope, element, attrs)
{
attrs.$observe('link',function(link)
{
$http.get('modules/test/files/' + link).success(function(response)
{
var htmlText = converter.makeHtml(response);
return element.html(htmlText);
});
});
}
};
});
的YouTube:
app.directive('myYoutube', function($sce) {
return {
restrict: 'EA',
scope: { code:'=' },
replace: true,
template: '<div style="height:400px;"><iframe style="overflow:hidden;height:100%;width:100%" width="100%" height="100%" src="{{url}}" frameborder="0" allowfullscreen></iframe></div>',
link: function (scope) {
scope.$watch('code', function (newVal) {
if (newVal) {
scope.url = $sce.trustAsResourceUrl("http://www.youtube.com/embed/" + newVal);
}
});
}
};
});
使用'$ compile'源 – charlietfl 2014-08-28 12:59:58
这适用于:http://jsfiddle.net/Fyysf/28/所以你可能需要'$ compile'的降价返回的HTML。 – 2014-08-28 13:04:17