angularjs-service

How should I reference services in my controller functions without using scope?

♀尐吖头ヾ 提交于 2019-12-10 18:02:50
问题 After reading several articles on avoiding scope soup and referencing the Google Guidelines for building controllers I have been left with one burning question. How should I reference my injected dependencies within my controller? My approach thus far is to put the services on my object but I'm not exactly happy with that as now my services are exposed to the outside world (the template markup). What is the correct approach to build a controller without directly referencing $scope, and have

Referencing multiple API calls in one Service (Angular)

我们两清 提交于 2019-12-10 15:49:42
问题 I am accessing an API via Angular $http requests to gather information for different football teams. If I were to be only accessing one team, this would be fine - I would create a Service that made the call, then reference the Service function in my controller. However, I want to do this on numerous teams, without having to create a separate Service module for each one. Service app.factory('APIService', ['$http', function($http) { return $http.get('http://API/team/1204?Authorization=xxxxx')

How to override / change AngularJS value of value provider

ぃ、小莉子 提交于 2019-12-10 14:56:20
问题 I want to override value- angular.module("data", []).value('apiBase', '/api1/data') at runtime, I tried to modify it with- angular.module("data").value('apiBase', '/someotherapi/data') in some service/controller, but it failed, it didn't override the value of apiBase. I tried to inject apiBase in my controller and change it. angular.module('data').controller(function(apiBase){apiBase = '/someotherapi/data'}) it failed. Then I tried change the apiBase defination to an object like angular

Angular how to deal with unavailable URLs requested by $http.get or $http.jsonp, which are executed by $q.all()

回眸只為那壹抹淺笑 提交于 2019-12-10 12:20:35
问题 I've the following code: eventResourcesCall = $http.jsonp('https://apicall/to/serverA'); eventsDetailsCall = $http.get('https://apicall/to/serverB'); $q.all([eventResourcesCall, eventsDetailsCall]).then(function(values){ //process data manipulation and merging }); The problem is that serverA and ServerB might not be available sometimes, and when one of those are unavailable, the data processing code stops and I get an error similar to the one described below: GET https://apicall/to/serverA

AngularJS Interceptor Never Catches 401 Error

醉酒当歌 提交于 2019-12-10 11:17: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

Is there a loosly coupled way to update a parent directive from a dynamically created view/controller that is a child of the parent

末鹿安然 提交于 2019-12-10 10:27:32
问题 In my app I have window instances. The app can contain multiple windows and windows can contain multiple views. The views are children of each window instance. The windows and view creator are directive with an isolated scope. I want the views to be loosely coupled to their parent window and not have to something like $scope.$parent module.directive('window', function() { return { restrict: 'E', replace: true, templateUrl: 'windowTemplate.html', controller: 'windowController', scope: { config

How to pass $stateParams from ui-router to service in resolve? [closed]

偶尔善良 提交于 2019-12-09 16:42:57
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . I have a route to retrieve a single post and a service to query my API to do so. But I need to pass parameters from the URL to the service so that I can call the API properly. I cannot wrap my head around how to do that. This is what I have come up with so far. I left out what seemed not relevant for this

Use service into View AngularJS

心不动则不痛 提交于 2019-12-09 07:53:29
问题 I have issue with angularJS Service. I have simple service: angular.module('mainApp.services', []).factory('AuthService', function ($http) { //var currentUser = null; //var authorized = false; //AutoLogin for testing var currentUser={email: "example@example.com", id: "15"}; var authorized=true; // initial state says we haven't logged in or out yet... // this tells us we are in public browsing var initialState = false; return { initialState:function () { return initialState; }, login:function

AngularJS: PUT send data with URL but not as JSON data

[亡魂溺海] 提交于 2019-12-09 01:41:46
问题 Here is my UserService angular.module('userServices', ['ngResource']).factory('User', function($resource) { return $resource('/users/:userId', // todo: default user for now, change it {userId: 'bd675d42-aa9b-11e2-9d27-b88d1205c810'}, {update: {method: 'PUT', params:{profile: '@profile'}, isArray: false}} ); }); In my controller, I do $scope.save = function() { $scope.user.$update({profile: $scope.profile}); } But when I see the Network Tab in Chrome, I see Request URL:http://localhost:5000

Service functions outside Angularjs scope

☆樱花仙子☆ 提交于 2019-12-08 17:36:42
问题 I have created a service in angularJS that uses btford.socket-io module to interact with the server. Since in the service I have implemented some API that I use inside angular at the moment, but for later extension of the application I also need to give access to these API outside angular scope. So that in future one could just call the function without having the need to create controller and other stuff. At the moment I did this for a controller var myController = angular.element($('body'))