angularjs - ngTagsInput not populating from angular $http -



angularjs - ngTagsInput not populating from angular $http -

im finish angularjs newbie. on track.

i have datacontext configured like

(function () { 'use strict'; var serviceid = 'datacontext'; angular.module('app').factory(serviceid, ['common', '$http', datacontext]); function datacontext(common, $http) { var $q = common.$q; var service = { getcustomergroups: getcustomergroups }; homecoming service; function getcustomergroups() { var groups = []; $http({ method: 'get', url: '/api/getgroups' }). success(function (data, status, headers, config) { console.log(status); console.log(headers); console.log(data); groups = data; homecoming $q.when(groups); }). error(function (data, status, headers, config) { console.log(data); // called asynchronously if error occurs // or server returns response error status. }); homecoming $q.when(groups); } } })();

within view using ngtagsinput

<tags-input ng-model="groups" display-property="groupname" placeholder="add client group" enableeditinglasttag="false" class="ui-tags-input" replace-spaces-with-dashes="false"> </tags-input>

and controller

(function () { 'use strict'; var controllerid = 'customers'; angular.module('app').controller(controllerid, ['common','$scope','$http','datacontext', customers]); function customers(common,$scope,$http,datacontext) { var vm = this; vm.title = 'customers'; $scope.groups = []; function getgroups() { homecoming datacontext.getcustomergroups().then(function (data) { homecoming $scope.groups = data; }); } activate(); function activate() { var promises = [getgroups()]; common.activatecontroller(promises, controllerid) .then(function() { } ); } } })();

i not getting errors , can see right info returned in success method of $http. tag not populated. because tag calling datasource before $http has completed?

i not sure how $q.when works, returns promise not resolve it. should defer api.

so @ start set

var defer = common.$q.defer();

and later in success defer.resolve.

success(function (data, status, headers, config) { console.log(status); console.log(headers); console.log(data); groups = data; defer.resolve(data);

and see if works.

angularjs ng-tags-input

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -