Escape HTML text in an AngularJS directive

后端 未结 9 892
执念已碎
执念已碎 2020-12-05 07:12

Is there an angular JS command that will do HTML escaping on text? I am processing a custom directive and have need to escape some of the output which it generates.

9条回答
  •  北海茫月
    2020-12-05 07:55

    Sanitizing is one thing, but to display all characters and not "execute" HTML code I have used "text" function to set value.

    In your directive, to set value, instead of writing:

    element.html( scope.myValue );
    

    write:

    element.text( scope.myValue );
    

提交回复
热议问题