angularjs-factory

How pass values between controllers with a factory?

荒凉一梦 提交于 2019-12-11 14:49:23
问题 I'm trying to pass data between (I think) two child controllers. Trying to do this with a factory. testFactory.js app= angular.module('testApp'); app.factory('values', [function () { var testValues= { valueA: '' }; return { setValueA: function(a) { testValues.valueA= a; }, getValueA: function() { return testValues.valueA; } }; }]); In different JS files so different controllers. controller1.js (this one sets the value) angular.module('testApp') .controller('firstCtrl', ['$scope''values',

Create new ui-grid by using a factory: what is the scope - parameter to use the ui-grid-event-handler?

一个人想着一个人 提交于 2019-12-11 13:39:39
问题 I create an ui-grid in my controller by using an Factory-method, which creates an new Table-Object(ui-grid). But I got problems with setting up the scope in the ui-grid-event-handlers. See my js fiddle example for better understanding. In the jsfiddle you get now the error in the console: Cannot read property '$on' of undefined at Object.GridApi.registerEvent.feature.on.(anonymous function) [as navigate] If I change the handler-paramter to null, everything works fine, but... In my project,

angularjs changing factory object shared between controllers

馋奶兔 提交于 2019-12-11 12:49:03
问题 Is it possible to update the scope variable that points to a factory object, after the factory object is updated? If there are 2 angular controllers which share a factory object, if one of the controllers changes the factory object, it is not reflected in the scope variable of the other controller. Ex: http://jsfiddle.net/zjm0mo10/ The result will be "Factory foo.bar is 555" instead of "Factory foo.bar is 666" var app = angular.module('myApp', []); app.factory('testFactory', 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(

How to mock an object within an AngularJS factory method

谁都会走 提交于 2019-12-11 09:40:50
问题 I have created an Angular factory that has methods which handle saving code to a server. One of the factory methods contains a third party object which has a method which does the actual callout. I would like to test this code, but I can't work out how to mock out the third party object. I have set up a plunker with a Jasmine test. My aim for this test is just to successfully get the code to use my mock object rather than the ThirdPartySavingUtils object. Is that possible? var app = angular

AngularJS Error: $injector:unpr Unknown Provider githubProvider <- github <- MainController

非 Y 不嫁゛ 提交于 2019-12-11 03:47:55
问题 I'm trying to build my own service by following the example in the documentation for the factory methodology. I think I've done something wrong however because I continue to get the unknown provider error index.html <!DOCTYPE html> <html ng-app="githubViewer"> <head> <script data-require="angular.js@1.4.3" data-semver="1.4.2" src="https://code.angularjs.org/1.4.2/angular.js"></script> <link rel="stylesheet" href="style.css" /> <script src="script.js"></script> <script src="github.js"></script

AngularJS sharing data between factory & controller across modules

↘锁芯ラ 提交于 2019-12-11 03:16:24
问题 I have an angularjs app that has several modules. The main modules looks something like: var app = angular.module('mainMod', ['apiService']); app.controller('MainCtrl', function (Socket) { $scope.objects = {}; // do something with $scope.objects, etc. }); And then I have; var apiService = angular.module('apiService', ['ngResource']); // etc and; apiService.factory('Socket', ['$rootScope', function ($rootScope) { // create a websocket and listen for stuff // if something happens, update

AngularJS : Scope issue in $http success callback

偶尔善良 提交于 2019-12-10 20:25:23
问题 I'm using PHP to get data into my factory, which shows correctly in the success callback function within the controller. However, even after assigning the returned data to $scope.customers, it's not there if I do a console.log($scope.customers) after the callbacks, and my view's [ng-repeat] isn't picking it up either. Any idea why the scope of my data would be restricted to just inside the success callback if I'm assigning the returned data to my $scope object? var customersController =

Using a factory inside another factory AngularJS

廉价感情. 提交于 2019-12-09 08:30:38
问题 I have a module... angular.module('myModule', []); And then a factory angular.module('myModule') .factory('factory1', [ function() { //some var's and functions } ]); And then another factory angular.module('myModule') .factory('factory2', [ function() { //some var's and functions BUT I want to use some var's from factory1 } ]); But I want to use some variables from factory1 inside factory2, how can I inject factory1 into factory2? 回答1: This is what I would do: On Factory One angular.module(

AngularJS Best Practice - Factory with multiple methods

て烟熏妆下的殇ゞ 提交于 2019-12-07 13:56:16
问题 I have a factory that serves up three different $http.get methods. angular.module('myApp') .factory('getFactory', function ($http, $q) { return { methodOne: function () { var deferred = $q.defer(); $http.get('path/to/data') .then(function successCallback (data) { deferred.resolve(data); },function errorCallback (response) { console.log(response); }); return deferred.promise; }, methodTwo: function (arg1, arg2) { var deferred = $q.defer(); $http.get('path/to/' + arg1 + '/some/' + arg2 + 'more