angularjs-service

AngularJS inject service mock inside service tests

落爺英雄遲暮 提交于 2019-12-07 02:28:14
问题 I have been trying to test a service to no avail for some time now and was hoping for some help. Here is my situation: I have a service looking a little like this myModule.factory('myService', ['$rootScope', '$routeParams', '$location', function($rootScope, $routeParams, $location) { var mySvc = { params: {} } // Listen to route changes. $rootScope.$on('$routeUpdate', mySvc.updateHandler); // Update @params when route changes mySvc.updateHandler = function(){ ... }; ... ... return mySvc; }]);

AngularJS factory property isn't being updated in $scope when not using push()

倾然丶 夕夏残阳落幕 提交于 2019-12-06 22:51:27
问题 I have a factory that is retrieving the data from an external source. As soon as i get the data, i use a second factory to filter it by a certain criteria. The factory property is assigned to scope. Now when i do this in my factory, it doesn't update the scope: factory.foo = [{id:1,name:'foo'}]; // doesn't work therefor also the filterin in a second factory doesn't work factory.foo = Filter.filter(); // doesn't work while this works: factory.foo.push({id:1,name:'foo'}); // works Does anyone

AngularJS $location.path(path) not updating at first

狂风中的少年 提交于 2019-12-06 16:06:15
I have a piece of code where I call $location.path(name) and nothing seems to happens (at first). I can call console.log($location.path()) and it does show the new path -- but the view doesn't change. Chain of events (some asynchronous): I have two controllers (and matching views), MainCtrl and CpugraphCtrl, and a Service GetDataService and one external data API (Google). button in Main view calls function in MainCtrl that calls function in GetDataService that calls google client API gapi.client.load() with a callback to function in GetDataService, which uses $rootScope.$broadcast('GraphUpdate

AngularJS $http POST request different results with then and success

人走茶凉 提交于 2019-12-06 14:33:51
问题 Something is driving me nuts; maybe someone can help me out with the following? : I am using AngularJS 1.2.26 (have to because IE8 needs to be supported) I have to invoke some backend services that were initially build for a backbone frontend. I managed to do that in the following way: $http({ method: 'POST', url: url, headers: {'Content-Type': 'application/x-www-form-urlencoded'}, transformRequest: this._transformRequest, data: formData }) .success(function (data) { // bla bla not relevant }

AngularJS Interceptor Never Catches 401 Error

风流意气都作罢 提交于 2019-12-06 14:22:40
I'm using Angular v1.2.20 with the Ionic Framework . I have seen many articles and posts about how to handle 401 errors from the server by using an interceptor and pushing it into the $httpProvider.interceptors array. For some reason, 401 responses never get caught by the repsonseError function in my interceptor. The promise I am expecting to reject never rejects and my app just seems to hang ( loading:hide from below never gets called). I can see from my web debugging proxy that a 401 is definitely returned from the server. My interceptor: .factory('interceptorService', function($rootScope,

AngularJS. Best practice concerning proper two way data binding from a service

巧了我就是萌 提交于 2019-12-06 13:51:03
I have an 'Account' service which acts as a centralized data storage used in multiple controllers and views. This service will hold, besides getter and setter methods all data associated with two types of users, being a logged in user and an anomonous user. The idea behind this service is that it should be used as a centralized data structure which will keep all associated views and controllers in synch. Eg: If a user logs in whe will know his email and all 'newsletter subscription' fields can be prefilled. The current setup i use is as below. Note that each Async call on the server will

Angular JS Unknown Provider Error

三世轮回 提交于 2019-12-06 09:59:00
问题 I am getting this error in my angular js app and can't figure out what's causing the problem. It seems to be a common issue but all my troubleshooting hasn't helped at all. If anyone can point to waht the problem may be it would be appreciated. Thanks :) Error: [$injector:unpr] Unknown provider: ResultsServiceProvider <- ResultsService <- ResultsController Here is my code: app.js angular.module('resultsApp', ['ngRoute', 'nvd3', 'ngResource']) .config(['$routeProvider', function($routeProvider

How to check authentication and automatically redirect to login state with ui-router?

萝らか妹 提交于 2019-12-06 09:35:34
问题 so I have this function in my run in angularjs (running AngularJS v1.2.26) .run(function(....) { authService.authCheck(); $rootScope.$on('$routeChangeStart', function(event, next, current) { if (next.requireLogin) { if (!authService.isLoggedIn()) { $location.path('/login'); event.preventDefault(); } } }); })... when directly accessing a URL that requires authentication e.g. http://127.0.0.1:8080/secret , the function always redirects to the login path, clearly after debugging it for a while

Angular store value to service to acces on multiple pages

試著忘記壹切 提交于 2019-12-06 09:18:38
SOLUTION: It seemed that my .get() function invoked before I could update the variable 'something' and therefore it didn't show the updated variable. When I tested it on the real page it worked like a charm :) final FIDDLE note: I did add a return to the set function to immediately update the view. UPDATE: got my factory working alright but can't get the value bound to the factory .set() function. FIDDLE I’m building a manual to install a USB-network connector and need to store some variables to show the right content across multiple pages (within the same controller tough). After doing some

AngularJS : How to use the $q promise feature in this situation to wait for data to be ready?

假装没事ソ 提交于 2019-12-06 00:23:18
I have a Controller which starts an API call in a Factory . Currently I start the call, then I have a function after that call to check the status of the Array . However I'm not sure how to force it to wait here while the data is being gathered, thus the need for some kind of $q implementation. As you can see in the screenshot below, vs.tickers returns an empty Object, or Array. Then finally the console.log in GetTickersFactory fires: 1st Controller if (root.tickerType === 'portfolio') { // Call to factory to start the API GETS: GetTickersFactory.getTickers('portfolio'); // I then call a