Skip to content

Fix issue with an Angular $watch on the tree ng-model firing twice on every drop#396

Closed
OzzieOrca wants to merge 1 commit into
angular-ui-tree:masterfrom
OzzieOrca:fix-watches
Closed

Fix issue with an Angular $watch on the tree ng-model firing twice on every drop#396
OzzieOrca wants to merge 1 commit into
angular-ui-tree:masterfrom
OzzieOrca:fix-watches

Conversation

@OzzieOrca

Copy link
Copy Markdown

I have a $scope.$watch on the value bound to the ng-model of the tree. Every time a node is dropped, the source node is removed from its place in the model and the destination node is created causing 2 changes to the model. The watch picks up both of them.

The 2 lines that cause this are:

this.source.remove();
this.parent.insertNode(this.index, nodeData);

See: https://github.com/angular-ui-tree/angular-ui-tree/blob/master/source/services/helper.js#L137-L138

Moving dragInfo.apply() into the angular scope $apply fixes this issue. Changes to the models are now done as a single atomic operation inside the $apply.

If there is a better way to fix this let me know.

…o the models are done as a single atomic operation
@OzzieOrca OzzieOrca changed the title Watch on the tree model fires twice on every drop Fix issue with an Angular $watch on the tree ng-model firing twice on every drop Mar 2, 2015
@enkodellc enkodellc mentioned this pull request Mar 18, 2015
@Voles

Voles commented Apr 27, 2015

Copy link
Copy Markdown
Member

Should be fixed by #411. @OzzieOrca can you confirm?

@OzzieOrca

Copy link
Copy Markdown
Author

Yep this fixes it. Thanks!

@OzzieOrca OzzieOrca closed this Apr 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants