angularjs-service

Firebase's AngularFire in an AngularJS service

别等时光非礼了梦想. 提交于 2019-12-03 07:02:57
The best way of handling Firebase in AngularJS surely has to be from within a service, so it's available to all Controllers across the App. I just can't get it to work! ... I first tried using angularFire(new Firebase(url)) , hoping I could bind to the service's scope, but Angular complains that it cannot $watch it. So I tried angularFireCollection instead like this: app.factory('myService', function myService(angularFireCollection) { var url = 'https://myfirebase.firebaseio.com'; return { getAll: function(path) { var ref = angularFireCollection(new Firebase(url + '/' + path)); console.log(ref

How to use two AngularJS services with same name from different modules?

感情迁移 提交于 2019-12-03 06:40:38
问题 Supposed I have two modules for AngularJS, e.g. foo and bar , and both of them define a service called baz . In my application I depend on them by saying: var app = angular.module('app', [ 'foo', 'bar' ]); Then I can try to use the baz service in a controller by using app.controller('blaController', [ '$scope', 'baz', function($scope, baz) { // ... }]); How can I define which of the two services I'd like to use? Is there something such as a fully-qualified name? 回答1: The service locator looks

Stop $timeout when starting new controller

老子叫甜甜 提交于 2019-12-03 05:38:25
问题 I'm polling for my data every 2 seconds to keep them updated on the page. My problem is when I visit another page the timeout stays active. How can i cancel my timeout when I visit an new page? function IndexCtrl($scope, $timeout, RestData) { $scope.rd = {}; (function getRestDataFromServer() { RestData.query(function(data){ $scope.rd = data; $timeout(getRestDataFromServer, 2000); }); })(); } //EDIT I found a solution, but I'm not sure if it's a good one. When i save my timeout to the

AngularJS: How to handle success and error call backs with ngResource?

送分小仙女□ 提交于 2019-12-03 04:40:44
The docs does not give any idea about it. My REST enpoint might throw error $scope.delete = function(index) { Transaction.delete({transactionId: $scope.transactions[index].uuid}) }; I changed the above to following $scope.delete = function(index) { Transaction.delete({transactionId: $scope.transactions[index].uuid}) .success('transaction deleted'); }; But it fails TypeError: Object #<Resource> has no method 'success' at Object.TransactionController.$scope.delete (http://localhost:5000/static/app/js/controllers/transactionController.js:26:8) at http://localhost:5000/static/app/lib/angular

Uploading a file with AngularJS and bluimp on success callback of another form

∥☆過路亽.° 提交于 2019-12-03 04:38:56
问题 I have followed the following tutorial in order to integrate the notorious bluimp jQuery file uploader in my AngularJS project. After some research I found that in the options array, witihn the jquery.fileuploader.js file, there is an option called autoUpload, which when set to true upload the file automatically. I tried to disable it(false, undefined), but quickly I learned out that this causes the upload not to function at all, not even on the form submit. I need to trigger the upload

How to mock $window.location.replace in AngularJS unit test?

旧城冷巷雨未停 提交于 2019-12-03 04:32:33
问题 I've got the following service: angular.module("services") .factory("whatever", function($window) { return { redirect: function() { $window.location.replace("http://www.whatever.com"); } }; }); How to mock $window object in unit test to prevent reloading the page when running tests? I tried using spyOn($window.location, 'replace').andReturn(true); , but it didn't work (still got "Some of your tests did a full page reload!" error) and $provide.value('$window', {location: {replace: jasmine

Delay an angular.js $http service

江枫思渺然 提交于 2019-12-03 04:08:36
问题 I have some angular factories for making ajax calls towards legacy ASP.NET .asmx web services like so: module.factory('productService', ["$http", function ($http) { return { getSpecialProducts: function (data) { return $http.post('/ajax/Products.asmx/GetSpecialProducs', data); } } } ]); I'm testing on a local network so response times are "too" good. Is there a smart way of delaying the $http a couple of seconds from making the call to simulate a bad connection? Or do I need to wrap all calls

AngularJS: Performing $http request inside custom service and returning data

怎甘沉沦 提交于 2019-12-03 03:21:40
问题 I have defined a custom http service in angular that looks like this: angular.module('myApp') .factory('myhttpserv', function ($http) { var url = "http://my.ip.address/" var http = { async: function (webService) { var promise = $http.get(url + webService, { cache: true }).then(function (response) { return response.data; }); return promise; } }; return http; }); And I can access this service in my controller like so: angular.module('myApp') .controller('myCtrl', function (myhttpserv) { var

can't get service instance from $injector.get()

邮差的信 提交于 2019-12-03 03:05:22
I define a customer service named "greeting", but can't get the instance from $injector.get('greeting'). It will throw such error: Unknown provider: greetingProvider <- greeting . So which is the right way to get it? Following is the code: var app = angular.module('myDI', []); app.config(function($provide){ $provide.provider('greeting', function(){ this.$get = function(){ return function(name) { console.log("Hello, " + name); }; }; }); }); var injector = angular.injector(); var greeting = injector.get('greeting'); greeting('Ford Prefect'); You need to create the injector from the module. var

The better approach to design AngularJS services

可紊 提交于 2019-12-03 00:17:18
I'm writing an AngularJS client application that would interact with a REST server. To manage the client / server interaction I'm using the $resource abstraction. Actually I'm writing every resource as a separated service and injecting it only in the controllers that are gonna use it. I've started to develop using the angularjs-seed , so in my separed services.js file I've got an increasing number of services: angular.module('testReqService', ['ngResource']). factory('TestReq', function($resource){ return $resource('http://test-url.com/api/test', {}, {}); }); angular.module('registerService',