angularjs-factory

watch factory variable with Angular

我的梦境 提交于 2019-12-07 02:50:34
问题 My single page application has 2 controllers : the first is for my main menu and the second is for the view. They share data with this factory myApp.factory('MenuFactory', function(){ var factory = { Monitor: "doneJob", Control: "", Report: "", Display: "", setMonitor: function(value){ factory.Monitor = value; }, setControl: function(value){ factory.Control = value; }, setReport: function(value){ factory.Report = value; }, setDisplay: function(value){ factory.Display = value; } }; return

Angular JS Unknown Provider Error

三世轮回 提交于 2019-12-06 09:59:00
问题 I am getting this error in my angular js app and can't figure out what's causing the problem. It seems to be a common issue but all my troubleshooting hasn't helped at all. If anyone can point to waht the problem may be it would be appreciated. Thanks :) Error: [$injector:unpr] Unknown provider: ResultsServiceProvider <- ResultsService <- ResultsController Here is my code: app.js angular.module('resultsApp', ['ngRoute', 'nvd3', 'ngResource']) .config(['$routeProvider', function($routeProvider

Angular store value to service to acces on multiple pages

試著忘記壹切 提交于 2019-12-06 09:18:38
SOLUTION: It seemed that my .get() function invoked before I could update the variable 'something' and therefore it didn't show the updated variable. When I tested it on the real page it worked like a charm :) final FIDDLE note: I did add a return to the set function to immediately update the view. UPDATE: got my factory working alright but can't get the value bound to the factory .set() function. FIDDLE I’m building a manual to install a USB-network connector and need to store some variables to show the right content across multiple pages (within the same controller tough). After doing some

how to mock the backend for angularjs app?

天涯浪子 提交于 2019-12-06 03:45:45
I would like to test a factory method that runs $resource. My test would mock the real backend that does not exist yet. Here is a sample factory code: app.factory( 'Global', function( $resource ){ var Jogas = $resource('/jogasok/:id', {'id': '@id'}, { 'ujBerlet': {'method': 'POST', 'params': {'berlet': true}} }); var jogasok = Jogas.query(); return { getJogasok: function() { return jogasok; } }; }) My test would be to check that query was made. If I initialize my app with: app.run( function run ($httpBackend) { $httpBackend.whenGET('/jogasok').respond([ {id: 1, name: 'asdfasdf'}, {id: 2, name:

AngularJS - refresh view after http request, $rootScope.apply returns $digest already in progress

老子叫甜甜 提交于 2019-12-06 03:30:59
Hey guys so I am simply trying to load data when my app starts. However, the view loads faster than the http request(of course). I want to refresh my view once my data has been properly loaded because that data defines my view. I've tried $rootScope.apply from inside the factory where I do my http request, and I also tried directly doing the http request in my controller again with $scope.apply, and neither one worked as they both gave me "$digest already in progress" Any idea how can I set up my code to make my views refresh on data load? I will be having several different http requests and I

AngularJS Best Practice - Factory with multiple methods

早过忘川 提交于 2019-12-06 01:29:24
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/data') .then(function successCallback (data) { deferred.resolve(data); },function errorCallback

AngularJS : How to use the $q promise feature in this situation to wait for data to be ready?

假装没事ソ 提交于 2019-12-06 00:23:18
I have a Controller which starts an API call in a Factory . Currently I start the call, then I have a function after that call to check the status of the Array . However I'm not sure how to force it to wait here while the data is being gathered, thus the need for some kind of $q implementation. As you can see in the screenshot below, vs.tickers returns an empty Object, or Array. Then finally the console.log in GetTickersFactory fires: 1st Controller if (root.tickerType === 'portfolio') { // Call to factory to start the API GETS: GetTickersFactory.getTickers('portfolio'); // I then call a

watch factory variable with Angular

若如初见. 提交于 2019-12-05 05:46:05
My single page application has 2 controllers : the first is for my main menu and the second is for the view. They share data with this factory myApp.factory('MenuFactory', function(){ var factory = { Monitor: "doneJob", Control: "", Report: "", Display: "", setMonitor: function(value){ factory.Monitor = value; }, setControl: function(value){ factory.Control = value; }, setReport: function(value){ factory.Report = value; }, setDisplay: function(value){ factory.Display = value; } }; return factory; }); I would like to watch change on factory.Control , but i can't make it works. When i try this:

Angular JS Unknown Provider Error

点点圈 提交于 2019-12-04 15:03:17
I am getting this error in my angular js app and can't figure out what's causing the problem. It seems to be a common issue but all my troubleshooting hasn't helped at all. If anyone can point to waht the problem may be it would be appreciated. Thanks :) Error: [$injector:unpr] Unknown provider: ResultsServiceProvider <- ResultsService <- ResultsController Here is my code: app.js angular.module('resultsApp', ['ngRoute', 'nvd3', 'ngResource']) .config(['$routeProvider', function($routeProvider) { $routeProvider.when('/results', { controller: 'ResultsController', templateUrl: 'app/results

How to set a timeout to abort an $http.get() inside a factory or service?

和自甴很熟 提交于 2019-12-04 04:07:09
I have the following method getData(url) in a my factory which uses $http.get(url) to get data from an URL angular .module('az-app') .factory('WebServiceFactory', function ($http, $q) { var WebServiceFactory = this; WebServiceFactory.getData = function (url) { var deferred = $q.defer(); $http.get(url) .then( function (response) { deferred.resolve({ data: response }); }, function (rejected) { deferred.reject({ data: rejected }); } ); //Promise to be returned return deferred.promise; } It works fine but I need to abort the http.get and/or reject the promise so I can display an error message from