angularjs-service

AngularJS - Unable to call http serrvice using factory

▼魔方 西西 提交于 2019-12-25 08:03:58
问题 To resolve my issue I have gone through many articles on different sites, but none resolved it. I'm writing a simple AngularJS application. I'm quite new to Angular. I have written a factory method which call the $http service which gets the data from the web api. Web api is running fine and its returning the JSON object as expected. Angular Code var app = angular.module("app", []) .controller("controller", function ($scope, WebFactory) { $scope.data = "data"; $scope.error = "error"; $scope

AngularJS : When to use service instead of factory

落爺英雄遲暮 提交于 2019-12-25 06:31:14
问题 Please bear with me here. I know there are other answers such as: AngularJS: Service vs provider vs factory However I still can't figure out when you'd use service over factory. From what I can tell factory is commonly used to create "common" functions that can be called by multiple Controllers: Creating common controller functions The Angular docs seem to prefer factory over service. They even refer to "service" when they use factory which is even more confusing! http://docs.angularjs.org

How share Service dynamic data between Controllers and Directives

烂漫一生 提交于 2019-12-25 05:27:22
问题 I'd like to know what pattern to use, if I need my Service to share it's dynamic data between Controller, Directives, etc. The reason I mention dynamic, is because I'd like to load new data and this data needs to be available in any other Controller, Directive, etc. For example, if a Directive generates a UL LI, it would have to re-generate it if the data inside the Service has changed! I've initially opened the following ( How to create reset() method in Service that return promise? ) and

Error: .$save is not a function (AngularJS)

☆樱花仙子☆ 提交于 2019-12-24 17:43:24
问题 The non-GET instance action $save doesn't work in my example. I always get the Error, that $save is not a function. The problem is, I don't know where I have to define the $scope.example = new Resource(); , because in my example I'm using 2 Controllers. One for the table list with objects and the other one for my modal window, where you can take CRUD operations. The CRUD operations are defined in an angular service. The code is structured as follows: Servie of Resource: ... return { name:

AngularJS - AlertFactory open dialog behavior

巧了我就是萌 提交于 2019-12-24 14:23:25
问题 i'm creating an AlertFactory because ui.bootstrap.dialog doesn't works in my app. So i type follow code: http://jsfiddle.net/Premier/BHqKB/17/ enter code here It works very well if you click on the "Open dialog" button: on screen appear a dialog with my messages. I also register a listener on keydown: listener fires a broadcast event on which is registered a scope related function. This function calls openDialog to show the dialog. In this way angular doesn't interpolates arguments and alert

Unit-Testing a service in Controller with Jasmine in AngularJS

北城以北 提交于 2019-12-24 11:25:17
问题 In my Controller I've defined the following service: CrudService.getAllGroups().$promise.then( function (response) { $scope.groups = response; }, function (error) { //error code.. } ); Well, I want to test this service whether it gets a response or not. In test script at first I've defined a function to check whether the service is defined at all. Test code: describe('Ctrl: TestCtrl', function () { beforeEach(module('testApp')); var scope, CrudService, ctrl, backend; beforeEach(inject

How to create a object with properties that are sharable among controllers in AngularJS?

天大地大妈咪最大 提交于 2019-12-24 07:09:23
问题 This is a follow-up question to How to create this global constant to be shared among controllers in Angularjs? The answer provided allows a constant $webroot to be shared among controllers. app = angular.module('myApp', []); app.constant('$webroot', 'localhost/webroot/app'); app.controller('myController', ['$scope', '$webroot', function($scope, $webroot) { $scope.webroot = $webroot; }]); However, the problem is if I have 10 constants, then all 10 constants have to be injected into the

In my service-factory I lookup up a large dataset - I want to persist it and check for its existence to avoid calling it again

本秂侑毒 提交于 2019-12-24 06:38:15
问题 My service (factory) makes an API call and assigns response data to a variable: .factory('MedicationMatchingNamesFactory', ['$http', '$q', 'MedicationDisplayNamesFactory', function MedicationMatchingNamesFactory($http, $q, MedicationDisplayNamesFactory){ return { getMatchingNames: function(inputValue){ var matches = []; // I thought this may be set as null so I'm able to // differentiate it from the below array form (when exists) var allNames = null; MedicationDisplayNamesFactory

Typescript and AngularJS - Static methods vs services

泪湿孤枕 提交于 2019-12-23 15:00:39
问题 TL;DR: Static basic functionality that has to do nothing with angular - implement as an AngularJS service vs plain static exported class / methods? Long version : I've been programming in TS for about a month now, since we're refactoring our app to work with TS (preparing for angular 2.0). When started to go through some of our basic angular services, I was thinking - since it's so easy to implement static classes and methods - maybe some of our services shouldn't be services at all. Of

AngularJS: Using services in directives

99封情书 提交于 2019-12-23 12:19:31
问题 This is an angularjs app. I have a service that handles the loading of content (ajax). While the service is getting the content, a number of things throughout the app hide, later showing again (depending on the content returned). They might have the same scope, different scope, whatever. They just need to hide while content is loading, and then show when it's done. Pretty normal stuff. Right now, I have separate controllers watching a "loading" property of the service and using regular