javascript - AngularJS $http not firing get call -


i have question firing $http.get multiple sources in angularjs. code below quite simple: have $scope.test function click handler 1 button in html. $http.get works ok. have $http.get gets data server , creates basic primitives chart. simple , works well. , then, append button on every chart node , on button handler execute $http.get call. 1 doesn't work!

here code:

$scope.test = function () {     console.log('klic na id 1');     $scope.commoncontroller.getdata('orgunit/1?jsondepth=3')         .success(function(workpositiondata,status,headers,config) {             console.log('klic na id 1 ok');             $scope.workpositions = workpositiondata.workpositions;         }).error(function(data,status,headers,config) {             commoncontroller.error('pri branju delovnih mest je prišlo napake: '+data.description);         }); };   var options = new primitives.orgdiagram.config();     var itemb, itemc, itemd, iteme; var rootitem = new primitives.orgdiagram.itemconfig();  options.rootitem = rootitem; options.cursoritem = rootitem; options.hasselectorcheckbox = primitives.common.enabled.true;  var buttons = []; buttons.push(new primitives.orgdiagram.buttonconfig("add", "ui-icon-folder-open", "add0"));      options.buttons = buttons;  options.onbuttonclick = function (e, data) {     console.log('klic na id '+data.context.id);     $http.get('proxy/api/orgunit/' + data.context.id + '?jsondepth=3')     .success(function(workpositiondata,status,headers,config) {         console.log('klic na id '+data.context.id + ' ok');         $scope.workpositions = workpositiondata.workpositions;     }).error(function(data,status,headers,config) {         commoncontroller.error('pri branju delovnih mest je prišlo napake: '+data.description);     });                  };  $http.get('proxy/api/orgunit/tree?jsondepth=2') .success(function(orgunitsdata,status,headers,config) {     console.log('reading orgunit tree ok');      rootitem.title = orgunitsdata.orgunits[0].title;     rootitem.description = orgunitsdata.orgunits[0].description;             rootitem.id = orgunitsdata.orgunits[0].id;     rootitem.hasselectorcheckbox = false;     rootitem.image = "http://www.basicprimitives.com/demo/images/photos/a.png";      $scope.additems(rootitem, orgunitsdata.orgunits[0].subordinates, 0);     jquery(".basicdiagram").orgdiagram(options);   }).error(function(data,status,headers,config) {     console.log('reading orgunit not ok'); });  

i tried lot of combinations of creating chart (directive, separate template , controller, ...) nothing works. $http.get call button on chart note doesn't fire (nothing in network in chome developer tools).

but here interesing this: if execute test function time (click on html button), response test function and $http.get chart button. looks $http.get call chart button waiting , when appers, fires.

does have idea solution problem? output in console scenario execute test, execute chart button function, execute test (bolded console entries chart button function, nonbolded test function:

klic na id 1 klic na id 1 ok klic na id 4 klic na id 1 klic na id 1 ok klic na id 4 ok

if have idea please let me know, thing driving me crazy few last hours. update

i solved solution, found here https://github.com/angular/angular.js/issues/2794#issuecomment-18807158, wraped call function $scope.$apply.

$scope.$apply(function() {     console.log('klic na id ' + data.context.id);     $scope.commoncontroller.getdata('orgunit/' + data.context.id + '?jsondepth=3')     .success(function(workpositiondata,status,headers,config) {         console.log('klic na id ' + data.context.id + ' ok');         $scope.workpositions = workpositiondata.workpositions;     }).error(function(data,status,headers,config) {         commoncontroller.error('pri branju delovnih mest je prišlo napake: '+data.description);     }); }); 

best regards

starting angular 1.1.4 need call $http in context of angular digest loop. if not can manually call $scope.$apply(); after http call. see https://github.com/angular/angular.js/issues/2431#issuecomment-18566595


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -