angularjs指令 – 获取元素绑定的文本内容
发布时间:2020-12-17 17:56:10 所属栏目:安全 来源:网络整理
导读:如何根据角度js指令限制得到绑定的值:’A’? span directiverestrict {{binding}} /span 我尝试使用elem [0] .innerText,但它返回精确绑定“{{binding}}”而不是绑定的值 .directive('directiverestrict',function() { return { restrict:'A',link: functi
如何根据角度js指令限制得到绑定的值:’A’?
<span directiverestrict> {{binding}} </span> 我尝试使用elem [0] .innerText,但它返回精确绑定“{{binding}}”而不是绑定的值 .directive('directiverestrict',function() { return { restrict:'A',link: function(scope,elem,attr) { // I want to get the value of the binding enclosed in the elements directive without ngModels console.log(elem[0].textContent) //----> returns '{{binding}}' } }; }); 解决方法
您可以使用$interpolate服务,例如
.directive('logContent',function($log,$interpolate) { return { restrict: 'A',link: function postLink(scope,element) { $log.debug($interpolate(element.text())(scope)); } }; }); Plunker (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |