Sunday 15 February 2015

AngularJS: Using an angucomplete and data isn't always populated correctly on load -



AngularJS: Using an angucomplete and data isn't always populated correctly on load -

i writing forms adding , editing resources. using angucomplete-alt (https://github.com/ghiden/angucomplete-alt) , own dropdown directive choices database. in separate controller main form. regular text fields populate fine on edit form, have issues angucomplete , selects. scope info there on page load. have written function grab using id in url. don't populate unless reload page. how can them populate every time?

here function populate form:

$scope.popform = function(clientid) { var config = { params: {clientid: $stateparams.clientid}, headers: {'content-type': 'application/x-www-form-urlencoded'} }; $http.get('assets/php/clients/pop_client.php', config) .then(function(data) { var realstatus = data.data.status; if(realstatus == 'success'){ //set $scope json response $scope.client = data.data.client; //broadcast bunch of events info dropdowns $timeout(function() { $rootscope.$broadcast('settypedropdown', data.data.client.type); $rootscope.$broadcast('setcatdropdown', data.data.client.category); $rootscope.$broadcast('setteamdropdown', data.data.client.team); $rootscope.$broadcast('seta1dropdown', $scope.client.assigned1); $rootscope.$broadcast('seta2dropdown', $scope.client.assigned2); }); } }); };

i have controller takes care of selects, that's why there broadcasts of info downwards isolated scopes. here 1 of $on functions, since same. (there must less convoluted way of doing this...)

// options select options database // each instance of select controller $scope.$on('settypedropdown', function(event, type) { var = 0; $.each($scope.options, function(){ if (this.value == type){ $scope.client.type = $scope.options[i]; } i++; }); });

so, there improve way of doing this? because doesn't quite work...

edit: angucomplete-alts working now. convoluted selects worry about. wonder if wouldn't improve de-angularize them , not utilize directive.

angularjs angularjs-directive angular-ngmodel auto-populate

No comments:

Post a Comment