E
E
enchikiben2016-12-01 09:54:44
JavaScript
enchikiben, 2016-12-01 09:54:44

Object reference on ajax request in Angular?

Good afternoon! I get an object (tree) in the factory via ajax and assign it to the factory property like this:

fun: function () {
var _this = this;
$http.post('url', data).then(function (results) {
_this.data = results.data;
});
}

then I draw a tree in the view using (angular-tree-control) and there I change the properties of this object (the checkbox is stupidly removed and the property changes to true / false) in the angular-tree-control element the property changes, but not in _this.data .
And if _this.data is set without ajax request, then everything works as it should.

Tell me what is the trick of working with ajax?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
asdz, 2016-12-01
@asdz

Apparently what you get from the factory in the controller is not the same object that you work with in the factory itself. You just need to debug the code. I would implement the receipt of this data, via xmlhttp, in the service, and not in the factory.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question