我有一个定制的减价指令,效果很好。现在,我想在通过这个减价指令加载的内容中使用一个定制的youtube指令。youtube指令本身运行良好,但一旦我将其放入标记文件中,它就会被角忽略。
以下操作很好(但不是我想要做的):
.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指令。
在对减价指令进行评估之后,我需要做些什么来告诉角来评估这个指令呢?
为了完整起见,以下是指令:
减价:
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);
}
});
}
};
});发布于 2014-08-28 13:03:23
您确实使用.md指令将DOM添加到DOM文件中,但是由于它没有编译,angular不注册它。
像这样的事情应该有效:
$http.get('modules/test/files/' + link).success(function(response)
{
var htmlText = converter.makeHtml(response);
element.html(htmlText);
$compile( element.contents() )( scope );
return element;
});https://stackoverflow.com/questions/25549275
复制相似问题