3

So I currently have a directive for dynatree that is working fine. My question is is there a way from a controller to re-invoke a directive so that it rebuilds its self? Since my data is being stored in session storage and the updates to it are massive I can just fetch my new data set, swap it in session storage and rebuild the directive

2
  • 9
    If you're needing to do that, it sounds like you might be using Angular incorrectly. The directive should be using $watch to monitor your controller's model, which should allow itself to be rebuilt so to speak. Commented Apr 30, 2013 at 17:38
  • I believe that watch is redundant and can be replaced with receiving the data on your directive scope with '=', which is used for binding objects. See the example there: stackoverflow.com/questions/13294507/… Commented May 2, 2014 at 10:15

1 Answer 1

0

Within your directive, you can $watch for changes. Your $watch expression can monitor changes as simple as a property change, or it can monitor changes from properties that are several levels deep (deep object changes). You can even monitor according to the evaluation of a function. There is a lot of flexibility when it comes to what the directive watches and when and how to respond to those changes when they occur. For example, when conditions are met for rebuilding the tree (maybe through re-evaluation of a function, or maybe some external function that gets evaluated that changes a property), you can rebuild as you see fit.

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

Comments

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.