Search Posts

Category: watch

Setting up a listener with $watch in Angular JS

I have a service making two consecutive calls to an API asynchronously. I would like the app to wait for both to be resolved before proceeding and since one of calls may or may not be made, I believe $watch is the way to go versus nested or chained callbacks. var response_complete = {call1:false, call2:false}; $http.post(“myapi.com/slug”, data, header).then(function(res){ /* … */ response_complete.call1 = true; }); if(make_this_call==true){ $http.post(“myapi.com/anotherslug”, data, header).then(function(res){ /*…*/ response_complete.call2 = true; }); } […]

AngularJS SET service variable in controller, and use GET it everywhere else without $watch

Here is my basic service to SET and GET the value: .service(‘companyService’, [ function () { var self = this self.options = {} function CompanyService () { self.setOptions = function (newObj) { self.options = newObj } } return CompanyService() }]) In the global controller I call my $api factory which makes an http request (with promise) to get and set Company Options. I do this only once. .controller(‘global’, [‘$scope’, ‘$http’, ‘$api’, ‘$location’, ‘$translate’, ‘$rootScope’, ‘$timeout’, […]