angular-promise

AngularJS check if promise is empty or not

僤鯓⒐⒋嵵緔 提交于 2020-01-07 09:35:06
问题 Hi I have this code for the purpose of checking if there are users in the database, if it finds shows a list of users on a view, otherwise shows a view with form of user creation, but didn't work the check expression what I'm doing wrong users = Users.query(); users.$promise.then( function (data) { if (!data) { $location.url('/NewUser') } else { $location.url('/UsersList') } }); 回答1: It is probably returning an empty array in case nothing is found. Try checking the data length. if (data

Returning Data from Service to Controller with Asynchronous Callback

老子叫甜甜 提交于 2020-01-07 05:33:46
问题 I'm trying to upload image from Camera or gallery. I wrote all the code in the service. The controller must receive the complete url from the camera or gallery to show it in a slide box, but now nothing receive. Everything works, but I couldn't send back to the controller the url of the image. I think the error is because I'm trying to return the value before that the function "obtenerImagen" execute. I'm trying to implement Callbacks , but I think I did not implemented correctly. The

Angular Catch method not working with $http get request

安稳与你 提交于 2020-01-07 04:18:07
问题 I am trying to neatly manage service function calls from the controller while handling errors from the API. However when I do the following, I still get this is showing even with 403 and 404 errors in my console even when the API throws back a 403 or 404. I am assuming this could work if I added catch in my services file but I would prefer keep this managed from the controller. Is this possible? Controller: angular.module('EnterDataCtrl', []).controller('EnterDataController', ['$scope', 'Data

Angular: load environment properties before config/run

六月ゝ 毕业季﹏ 提交于 2020-01-07 02:49:35
问题 I'm developing a angular app, and this app has about a 10 configurable properties (depending on the environment and client). I had those properties in json config files, but this is really troublesome: there must be specific builds per env/company. So I would like to retrieve those properties once from the backend on app load. So in order to do this I created a Provider var app = angular.module('myApp', [...]); app.provider('environment', function() { var self = this; self.environment; self

Angular: load environment properties before config/run

可紊 提交于 2020-01-07 02:49:04
问题 I'm developing a angular app, and this app has about a 10 configurable properties (depending on the environment and client). I had those properties in json config files, but this is really troublesome: there must be specific builds per env/company. So I would like to retrieve those properties once from the backend on app load. So in order to do this I created a Provider var app = angular.module('myApp', [...]); app.provider('environment', function() { var self = this; self.environment; self

Cannot read property 'finally' of undefined while trying to make Rest call

旧巷老猫 提交于 2020-01-07 02:38:29
问题 I have a rest service defined in my project which acceps the url and callback function as a parameter. RestApiService service.requestFromApi = function(url, cb) { return service.request(config.ApiEndpoint.Base + url, cb); }; service.request = function(url, cb) { if(typeof cb !== 'function') { throw new Error('Function expected'); } $http.get(url).then(function(response) { if (response.status === 200) { if (typeof response.data === 'object') { return cb(response.data); } } }, function(response

Can't create a chaining promise with firebase and AngularJS, a FirebaseArray with two sequential calls to fetch data from two different tables linked

廉价感情. 提交于 2020-01-06 21:14:45
问题 I have the two following tables with services and categories: - servicecat - catid - name : "Category Name" - services - srvid1 : true - srvid2 : true - srvid3 : true - services - srvid - name: "Service Name" - Details: "blabla" - servicecat: - catid1 : true - catid2 : true I'm trying to build a firebaseArray to show when a user click on a service its information and categories. <script> var app = angular.module("sampleApp", ['firebase']); var fb = firebase.database().ref(); app.factory(

Can't create a chaining promise with firebase and AngularJS, a FirebaseArray with two sequential calls to fetch data from two different tables linked

混江龙づ霸主 提交于 2020-01-06 21:14:15
问题 I have the two following tables with services and categories: - servicecat - catid - name : "Category Name" - services - srvid1 : true - srvid2 : true - srvid3 : true - services - srvid - name: "Service Name" - Details: "blabla" - servicecat: - catid1 : true - catid2 : true I'm trying to build a firebaseArray to show when a user click on a service its information and categories. <script> var app = angular.module("sampleApp", ['firebase']); var fb = firebase.database().ref(); app.factory(

Service process http.get results into new array and return to calling controller

。_饼干妹妹 提交于 2020-01-06 09:05:35
问题 I am wanting to keep biz logic in service and return array object of values wanted to my controller. service.getBooking($scope.bookingId).success(function (data) { $scope.booking = data; console.log("3 storeno: " + $scope.booking.Storeno); In my service I have: testLabApp.factory('service', ['$http', function ($http) { var getBooking = function (bookingId) { console.log("[getBooking] bookingId = " + bookingId); var config = {headers: { 'Accept': 'application/json;odata=verbose' }}; return

calling a promise within a promise , with $q.all [duplicate]

匆匆过客 提交于 2020-01-06 06:53:52
问题 This question already has an answer here : multiple promises running in parallel, $q.all needs chaining? (1 answer) Closed 2 years ago . I have multiple api requests which can run in parallel. getlocations, getstates, get territories can make a request in parallel. however once i have the states list from getstates() call, i need to make an api request for each individual state and parse the state object. Here is the code that i have so far, Is it ok to call a promise within a promise this