大佬教程收集整理的这篇文章主要介绍了AngularJS:非标准属性的ng-src行为?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
正如预期的那样,我遇到了古典的表达式问题不能及时解决,我的浏览器发送请求到R_162_11845@y.media.com/{{video.src}},而不是my.media.com/somevideo.mp4
不幸的是,我面对同样的问题,有几个属性(海报,flashvars,占位符等)。我将如何创建与ng-src或ng-href指令相同的行为?我尝试寻找相关的源代码,但我没有找到它。这是一个片段,展示了有问题的HTML,
<video controls="controls" poster="{{mediaModel.mediaFile2}}" width="300" height="150"> <source ng-src="{{mediaModel.mediaFilE}}" type="{{mediaModel.contentTypE}}" /> <object type="application/x-shockwave-flash" data="http://player.longtailvideo.com/player.swf" width="300" height="150"> <param name="movie" value="http://player.longtailvideo.com/player.swf" /> <param name="allowFullScreen" value="true" /> <param name="wmode" value="transparent" /> <param name="flashVars" value="{{'controllerbar=over&image=' + media.mediaFile2 + '&file=' + mediaModel.mediaFilE}}" /> <img ng-src="{{mediaModel.mediaFile2}}" width="300" height="150" title="{{mediaModel.uploadedTimE}}" /> </object>@H_502_6@
下面我粘贴了代码为ngSrc,这有趣的是看起来并不复杂,关键的线似乎是优先级:99,根据旁边的注释,优先级为99的指令将在属性一直运行插值。
// ng-src,ng-srcset,ng-href arE interpolated forEach(['src','srcset','href'],function(attrName) { var normalized = directiveNormalize('ng-' + attrName); ngAttributeAliasDirectives[normalized] = function() { return { priority: 99,// it needs to run after the attributes arE interpolated link: function(scope,element,attr) { attr.$observe(normalized,function(value) { if (!value) return; attr.$set(attrName,value); // on IE,if "ng:src" directive declaration is used and "src" attribute doesn't exist // then calling element.setAttribute('src','foo') doesn't do anything,so we need // to set the property as well to achieve the desired effect. // we use attr[attrName] value since $set can sanitize the url. if (msiE) element.prop(attrName,attr[attrName]); }); } }; }; });@H_502_6@鉴于上述情况,实施自己的指令应该是微不足道的。
以上是大佬教程为你收集整理的AngularJS:非标准属性的ng-src行为?全部内容,希望文章能够帮你解决AngularJS:非标准属性的ng-src行为?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。