angularjs-service

AngularJS - extending module with own types / providers

∥☆過路亽.° 提交于 2019-12-03 00:13:58
I want to ad a new (dialog) type to angular, so I could use it just like I use module.directive , module.filter , module.controller to register directives, filters and controllers. I want to register my instances of dialog type this way: module.dialog('prompt',function(dependencies){ return { templateUrl:'prompt.html', controller:function($scope){}, something:'value' } }); I also want to be able to use registered dialogs in controllers (dependency injection) module.controller('ListCtrl',function($scope,prompt){ $scope.deleteItem = function(item){ prompt('Do you want to delete this item?').then

AngularJS ui-router: how to resolve typical data globally for all routes?

喜欢而已 提交于 2019-12-02 23:13:38
I have an AngularJS service which communicates with the server and returns translations of different sections of the application: angular .module('utils') .service('Translations', ['$q','$http',function($q, $http) { translationsService = { get: function(section) { if (!promise) { var q = $q.defer(); promise = $http .get( '/api/translations', { section: section }) .success(function(data,status,headers,config) { q.resolve(result.data); }) .error(function(data,status,headers,config){ q.reject(status); }); return q.promise; } } }; return translationsService; }]); The name of the section is passed

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

旧城冷巷雨未停 提交于 2019-12-02 17:48:05
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 webService = 'getUser?u=3' myhttpserv.async(webService).then(function (data) { console.log(data); }) });

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

醉酒当歌 提交于 2019-12-02 17:47:37
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 manually, say within another callback, or by a click event. can that be done?. code: app.directive(

Retrieving data out of post success from separate controller angularjs

南笙酒味 提交于 2019-12-02 17:28:16
问题 I am writing a simple service that uploads a file and posts it to a Spring controller. The controller manipulates this data and returns several objects as JSON. I am working with the following Angular service: myApp.service('fileUpload', [ '$http', function($http) { this.uploadFileToUrl = function(file, uploadUrl) { var fd = new FormData(); fd.append('file', file); $http.post(uploadUrl, fd, { transformRequest : angular.identity, headers : { 'Content-Type' : undefined } }) .success(function

Delay an angular.js $http service

烂漫一生 提交于 2019-12-02 17:28:14
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 to the factory methods in a $timeout ? $timeout(function() { productService.getSpecialProducs(data)

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

笑着哭i 提交于 2019-12-02 17:01:39
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.createSpy()}}) , but I was getting an error ( Error: [ng:areq] Argument 'fn' is not a function, got Object

How do I prevent angular-ui modal from closing?

拥有回忆 提交于 2019-12-02 14:25:18
I am using Angular UI $modal in my project http://angular-ui.github.io/bootstrap/#/modal I don't want user to close the modal by pressing on backdrop. I want a modal can only be closed by pressing close button which I have created. How do I prevent modal from closing ? artur grzesiak While you creating your modal you can specify its behavior: $modal.open({ // ... other options backdrop : 'static', keyboard : false }); Sachin G. backdrop : 'static' Will work for 'click' events but still you can use "Esc" key to close the popup. keyboard :false to prevent popup close by "Esc" key. Thanks to

Retrieving data out of post success from separate controller angularjs

☆樱花仙子☆ 提交于 2019-12-02 10:21:42
I am writing a simple service that uploads a file and posts it to a Spring controller. The controller manipulates this data and returns several objects as JSON. I am working with the following Angular service: myApp.service('fileUpload', [ '$http', function($http) { this.uploadFileToUrl = function(file, uploadUrl) { var fd = new FormData(); fd.append('file', file); $http.post(uploadUrl, fd, { transformRequest : angular.identity, headers : { 'Content-Type' : undefined } }) .success(function(data) { console.log("upload successful") //console.log(data) namesandaddresses = data; }) .error(function

AngularFire $remove item from Array using a variable in Firebase reference does not work

旧巷老猫 提交于 2019-12-02 09:40:48
问题 I've been struggling with the following problem: I'm trying to delete a 'Post' item from a Firebase Array with the $remove AngularFire method which I have implemented in a Angular Service (Factory). This Post is a child of 'Event', so in order to delete it I have to pass this Service a argument with the relevant Event of which I want to delete the post. This is my controller: app.controller('EventSignupController', function ($scope, $routeParams, EventService, AuthService) { // Load the