My directive stops working combined with another.. Angular.js

那年仲夏 提交于 2019-12-12 04:48:44

问题


I have a directive to edit a field dynamically called "click-to-edit". If I click on an item, I can edit it without problems.

<span ng-click="ignoreClick($event);" >
  <a href='' click-to-edit item="faq" ng-model='faq.pregunta'
     typeinput='textarea'>{{faq.pregunta}}
  </a>

I have a filter that highlights a word when it is found, this filter is called "highligth". If I add the line

ng-bind-html="faq.pregunta | highlight:search.pregunta"

I can not click to edit the field.

but the filter works for me to highlight. I need to not miss the functionality of editing the fields without it being damaged when the text is highlighted. How can I fix this?

https://jsfiddle.net/jv5o6s8y/


回答1:


The issue with ng-bind-html is that it replaces the directive's template, that is why you are not able to click inside the directive (original ng-click with toggle will not work), it doesn't contain the initial template. You should highlight the text somewhere inside your directives template, like:

<div class="hover-text-field" ng-show="!editState" ng-click="toggle()" ng-bind-html="model | highlight:search.pregunta"></div>

, check this working jsfiddle.



来源:https://stackoverflow.com/questions/44266722/my-directive-stops-working-combined-with-another-angular-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!