In this example, I have an input with the attached directive. The directive is designed to display messages near the entrance. There is another input and a button for adding messages. After displaying some messages, focusing on the input with the attached directive should clear the messages. http://jsfiddle.net/viro/WBqxf/
So, I have a directive with an isolated model, and I'm trying to update the model when an element that has a directive goes into focus. It seems that I should wrap event callbacks in a scope. $ Apply if I want to update the model:
element.on('focus',function(){ scope.$apply(function(){ console.log("focus !"); scope.tstMsg=[]; }) });
I suppose I need to wrap it in $ apply, because I use jqlite eventbackback, and I assume that they trigger angularJS “out”, but I did not find it clearly stated in the docs.
Am I doing it right or is it hacking?
Is there a better way to do this?
source share