angularjs-service

Angularjs issue in relacing Ajax request with promises in service

余生长醉 提交于 2019-12-11 16:20:28
问题 For my Angularjs application in services I have used Ajax call to get the data and is as follows : var originalRequest = $.ajax({ async : false, url : "/dash/dashboard2ajax.do", type : "POST", data : { action : 'getNetSpendOverTime', customerId : selectedAccTd, carriersId : selectedCarriers, fromDate : formattedFromDate, toDate : formattedToDate }, dataType : "json", success : function(originalRequest) { var res = originalRequest; data = res.ResultSet.Response; } }); Then I just return (data)

How to pass data from one asynchronous to another asynchronous function in AngularJS

。_饼干妹妹 提交于 2019-12-11 15:39:18
问题 How to pass global variable value from one function to another function in angular? I have 2 global variables as: $scope.genewtId = null; $scope.data1 = null; I have 2 angular functions which look as below: $scope.getID = function() { Service1.getId("abc").then(function(response){ $scope.genewtId = response.data[0].Id; console.log($scope.genewtId); }, function(error){ console.log(error.statusText); }); }; $scope.getDetails = function() { Service2.getDetails($scope.genewtId).then(function

AngularJS : get object by id from factory

梦想的初衷 提交于 2019-12-11 11:34:19
问题 I have a factory to get an array with all my clientes from the database. Then i need to filter this array by the person id and show only it's data in a single page. I have a working code already, but it's only inside a controller and I want to use it with a factory and a directive since i'm no longer using ng-controller and this factory already make a call to other pages where I need to show client data. This is what i tried to do with my factory : app.js app.factory('mainFactory', function(

Controlling order of operations with services and controllers

≯℡__Kan透↙ 提交于 2019-12-11 11:19:27
问题 I have two services - one to store user details and the other to make a call to retrieve those details: userService stores user details to be used across the entire app (i.e. injected in controllers, services, etc.) function userService($log) { var id = ''; var username = ''; var isAuthenticated = false; var service = { id: id, username: username, isAuthenticated: isAuthenticated }; return service; } authService is used (hopefully just once) to retrieve the user details from a Web API

Unit test a service : AngularJS

吃可爱长大的小学妹 提交于 2019-12-11 06:01:58
问题 I have few questions with to write a proper unit test for a service using jasmine as framework and karma as test runner. here is what i implemented in example-service.js : export default class ExampleService { constructor($resource, $http, $urlMatcherFactory) { 'ngInject'; this.$resource = $resource; this.$http = $http; this.$urlMatcherFactory = $urlMatcherFactory; } exampleMethodOne() { //some code lines } exampleMethodTwo() { //some code lines } } ExampleService.selector = 'myExampleService

Can a service that provides a single gettable/settable variable be simplified?

你说的曾经没有我的故事 提交于 2019-12-11 05:27:30
问题 I have a service like this: var app = angular.module('someModule'); app.factory('token', function() { var token = null; return { get: function() { return token; }, set: function(tokenIn) { token = tokenIn; } }; }); I'd rather have something like this: app.variable('token', null); After 5 years of POJOs, I'm have a small but intense hatred for getter/setters. Is there a better way to do this with angular? provide.constant and provide.value didn't seem to fit the bill. I couldn't find a plugin

AngularJS Amplitude Service Not Acting as Singleton

心不动则不痛 提交于 2019-12-11 05:08:31
问题 I have recently posted a similar question, but this is not a duplicate. Apologies for the code heavy post but I wanted to provide as much context as possible. I am having an issue with defining the analytics tool, 'Amplitude' as a service in my Angular.js application. Services are supposed to act as singletons throughout an application (source), so I am confused to be getting the following behavior. In my app.js file, I call AmplitudeService.logEvent('EVENT_NAME') in a .run function which

Is it possible to create an AngularJS service without a module?

て烟熏妆下的殇ゞ 提交于 2019-12-11 04:55:51
问题 In AngularJS there is a short form to create controllers, so you do not have to use a module for this. This short form is to simply define a function function FooController ($scope) { // ... } and reference it from the HTML markup using ng-controller : <div ng-controller="FooController"> ... </div> Now, my question is, whether there is a similar "short form" to define services? In other words: Can you define (and use) a service without using a module? Please note that I know that it perfectly

Angular “Unkown Provider” - how to use a factory within routeProvider configuration?

ぃ、小莉子 提交于 2019-12-11 04:03:50
问题 While playing around with Angular I try to understand better how to use factory, services, constants, routing and other core concepts. So I build a simple demo app with node, express, jade and angular. Now I would like to use a value inside the routeProvider configuration. I created a constant, this works fine. To make it more flexible for future usage I build a factory then, but this fails with "unknown provider". Is this a question of instantiation sequence in Angular? Why I cannot inject

AngularJs: pass $scope variable with service

百般思念 提交于 2019-12-10 20:49:46
问题 I have two controllers and in one of them I declared a $scope variable that I would like visible in the second controller. First controller app.controller('Ctrl1', function ($scope) { $scope.variable1 = "One"; }); Second Controller app.controller('Ctrl2', function ($scope, share) { console.log("shared variable " + share.getVariable()); }); I researched the best Angular approach and I found that is the use of service. So I added a service for Ctrl1 Service .service('share', function ($scope) {