I am using https://github.com/ezraroi/ngJsTree and I have come across the following problem.
My ng-model is a AJAX request and when my controller fires, data is not yet ready, so it does not render anything.
<div ng-controller='myCtrl'>
<div js-tree="treeConfig" ng-model="treeData" should-apply="ignoreModelChanges()" tree="treeInstance" tree-events="ready:readyCB;create_node:createNodeCB"></div>
</div>
Depending on the structure of your application, you may have a few alternatives to handle this situation. Create a service that is responsible for reading the data. Then you can do one of the following:
make router to wait till the reading is resolved before navigating to the view. Here is a related SO question: AngularJS $http.get with resolve
add event listener to the controller and make service to emit/broadcast event when the data is ready.
In both cases, you may want to read data from service.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.