3

Can I prevent angular watcher creation for element attributes using bind-once or angular-once directive?

I am using Angular Once directive.

How to use in following

<div contentKey={{conKey}}></div>

This working fine

Before Angular Once

<div>{{conKey}}</div>

After Angular Once

<div><any once-text="conKey"></any></div>

1 Answer 1

4

According to the angular-once api documentation, attributes can be "bound once" using the following syntax: once once-attr-*="value"

So for your attribute, it would be: <div once once-attr-contentKey="conKey"></div>

This is a little strange, because the parallel angular directive (ng-attr) can accept an expression in double curly braces (like you are trying to do). <div ng-attr-contentKey={{conKey}}></div>

Here is a plunkr comparing the two.

Sign up to request clarification or add additional context in comments.

1 Comment

Lib author here :) It's little strange, but adding interpolation ({{ }}) automatically adds watchers and lib is all against that, hope makes sense

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.