angular-promise

Angular 2: when i change a variable in a promise.than in ngOnInit the view doesn't refresh

久未见 提交于 2019-12-25 09:15:58
问题 I created a short example of an Angular 2 application built with NativeScript , what I expect is the variable foo to be "foo" at the beginning, then the ngOnInit() first change it to "bar" and then the promise return and I should see "foobar" in the Label, but instead I see "bar". The execution is as expected as I can see in the logs: JS: afterBar JS: promise new JS: promise than component.ts foo:String="foo"; ngOnInit() { this.foo = "bar"; console.log("afterBar"); var promise = new Promise(

Sorting $q.all() responses not working

假装没事ソ 提交于 2019-12-24 20:59:46
问题 My $q.all() is working fine. The below code is in my primary service and when done everything is returned to the controller correctly. However I am trying to pre-sort the final array returned to the controller its not working. The sort function itself works - its the identical function in my controller that I use to manually sort the results on my template page. Its just the initial results don't come back sorted. I know its an async issue, but can't figure out where the sort needs to go

Why getting the value after clicking it twice? + Promise

空扰寡人 提交于 2019-12-24 20:32:53
问题 I have a lack of understanding asynchronous operation while I'm dealing with a promise function in angular. So basically, I'm trying to get a value from a promise method and assign it to a global variable in a component. However, I am unable to retrieve the value when I click on a button once and it finally starts to show the value after I clicked on a button once more. Error I get when I clicked it once : Cannot read property 'matchId' of undefined Value I get after I clicked it twice : 3

Firestore transaction produces console error: FAILED_PRECONDITION: the stored version does not match the required base version

£可爱£侵袭症+ 提交于 2019-12-24 16:41:42
问题 I have written a bit of code that allows a user to upvote / downvote recipes in a manner similar to Reddit. Each individual vote is stored in a Firestore collection named votes , with a structure like this: {username,recipeId,value} (where value is either -1 or 1) The recipes are stored in the recipes collection, with a structure somewhat like this: {title,username,ingredients,instructions,score} Each time a user votes on a recipe, I need to record their vote in the votes collection, and

Promise create custom fail is not a function Angularjs error?

依然范特西╮ 提交于 2019-12-24 13:26:32
问题 As i am trying to use promise to create html5 directory functions in angularjs. but it shows error as promise not defined. Angular file:- $scope.createDirectory = function(dirName,dirLocation){ fileManager.createDirectory(dirName,dirLocation) .then(function(data){ console.log(data, "dir created"); }).fail(function(err){ console.log(err,"dir err while creating"); }); }; JS File:- var fileManager = { createDirectory: function(directoryName,dirLocation){ var makePromise = new Promise(function

Angular custom filter with promise inside

ぐ巨炮叔叔 提交于 2019-12-24 13:25:02
问题 What I am trying to achieve is using a filter that will return success or error from the ret() function. With the code below it returns {} , which is probably its promise. .filter('postcode', ['$cordovaSQLite', '$q', function($cordovaSQLite, $q) { return function(PostCodeID) { function ret() { var def = $q.defer(); ionic.Platform.ready(function() { if (window.cordova) { var db = $cordovaSQLite.openDB({ name: "msddocapp.db" }); } else { var db = window.openDatabase("msddocapp.db", "1", "ES

AngularJS - Script stops running at factory function with promise return

て烟熏妆下的殇ゞ 提交于 2019-12-24 12:09:19
问题 I've been learning/working on a newbie project which is basicly a simple task manager(similiar to those todo list projects). And I designed a user login page for this project and here is how it works. So I have two functions siteLogin() for logging in and inside it I want to use second function showTasks() after user logs in which returns the usertasks it gets from API ( promises I know ). So first I needed to return a value from a $http inside the showTasks() function but I ended up

angularjs deferred promise not deferring

佐手、 提交于 2019-12-24 04:09:12
问题 struggling to get promises working correctly in angularjs service provider i've read the docs as well as numerous examples (here, here and here) and i think i've got my syntax ok (although obviously something is wrong) app module and controller look like var myApp = angular.module('myApp', []); myApp.controller('Controller_1', ['$scope', 'Service_1', function($scope, Service_1) { var myName = "Ben"; Service_1.slowService(myName) .then(Service_1.fastService(name)); $scope.myName = myName; }]);

AngularJS promise returning empty object

给你一囗甜甜゛ 提交于 2019-12-24 01:54:51
问题 Basically what I want to do, is to assign some model value from function call that resolves promise. Like so value = someFun() This is a service from which I call this function app.factory('SomeService', function($q) { return { someFun: function() { var d = $q.defer(); try { d.resolve("hi"); } catch (e) { d.reject(e); } return d.promise.then(function(text){ return text; }); } }; }); Here is the HTML code <div ng-init="value = 'yes'"> <pre>{{value |json}}</pre> </div> <button type="button" ng

AngularJS two http get in one controller make problems

时光怂恿深爱的人放手 提交于 2019-12-24 00:55:46
问题 i have two http GET in one controller and sometimes it works and two of them are working. sometime only one http Get is work. and sometimes none of them is shown. any suggestions? }).controller("nextSidorAdminCtrl", function($scope,$rootScope,$http,$location,$state) { $http.get("/ShiftWeb/rest/admin/getallsettingtime") .then(function(response) { $scope.settingtimes = response.data; }); $http.get("/ShiftWeb/rest/admin/nextsidor") .then(function(response) { $scope.nextsidor = response.data; });