失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > Angularjs $compile使用示例

Angularjs $compile使用示例

时间:2019-08-24 20:38:19

相关推荐

Angularjs $compile使用示例

代码如下:

var infographicModule = angular.module('infographicModule',[]); infographicModule.directive('bodyTextInfographic', ['$compile','$timeout','jsonService',function($compile,$timeout,jsonService) {return{restrict: 'C',link: function (scope, iElement, iAttrs) {var tempURL=scope.source['default'].href || scope.source['medium'].href || scope.source['small'].href;if(tempURL){var resultingElement = "<div class='infographic_iframe_container'>"+"<iframe onLoad='infoloadfun()' class='infographic_iframe' frameborder='0' scrolling='auto' src="+ tempURL +"></iframe>"+"</div>";var linkFn = $compile(resultingElement);var newElement = linkFn(scope);iElement.replaceWith(newElement); //这里的iElement也可以替换成页面上的任意元素}}}}]);

//另一使用示例:(iElement也可以替换成页面上的任意元素)

var jqEle = floatMenuContentEl.find("."+viewName+"Pane");

var tplPath = HTML_RENDITION.documentsPath_version +'views/'+viewName+'Pane.html?ts=' + scope.timestamp;

var tpl = $compile("<div style='width:280px;' ng-include=\"'"+tplPath+"'\"></div>")(jqEle.scope());

jqEle.html(tpl);

相比传统的template,$compile更为灵活

如果觉得《Angularjs $compile使用示例》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。