angularjs,angularjs-service,angularjs-factory,angularjs-provider
Since factories are singletons you will need to use a method in your factory to create your service each time. Change your service to have a create method that returns your service that does the incrementing: myApp.factory('myService', function() { return { create: function () { return { counter: 0, increment:...
angularjs,cordova,cors,ionic-framework,angularjs-factory
The API at https://api.random.org/json-rpc/1/invoke is not responding with header Access-Control-Allow-Headers: accept, content-type. Therefore the browser is rejecting the CORS request. You can work-around the issue by using a CORS proxy. There are several projects out there you can use for testing (e.g. cors-anywhere comes as a npm module). I prepared...
angularjs,angularjs-controller,angularjs-factory
In general in AngularJS if you want to communicate between controllers you should use a service. Create a service and have each of your controllers (geo and date) set values in the service that would then control the value it returns to the SunListCtrl that you use in the ng-repeat....
javascript,angularjs,angularjs-scope,angularjs-controller,angularjs-factory
You could achieve this by creating factrory and place this method inside there, and access this method by injecting factory dependency app.factory('DataService', fucntion($http){ var baseUrl = "http://www.somewebsite.com/api"; var getData = function(extendedUrl, successCallback, errorCallback){ return $http.get(baseUrl + extendedUrl).success(successCallback).error(errorCallback); } return { getData: getData } }); Controller module.controller('directoryCategoryListing', function($scope, $http, $rootScope, DataService)...
angularjs,angularjs-scope,angularjs-controller,angularjs-factory
You are not injecting your service correctly into your controllers - see this fiddle Also remove the data param from you getName() call: <button ng-click="getName()"> ...
javascript,angularjs,angularjs-factory
$scope.uacForm will just be your promise, not the actual value. You need to put the data somewhere on the scope when the promise is resolved to be able to reach it from the view. Ie factory1.getData().then(function(data, status, headers, config) { $scope.uacForm = data.data2; console.log($scope.uacForm) }, function(data, status, headers, config) {...
javascript,angularjs,angularjs-factory,angularjs-compile
personally I wouldnt put that in a factory but add a directive to compile the code or do it in the controller.... if I understood what you are trying to do correctly this is what I suggest: for a static html you already have the ng-bind-html directive... and if you...
angularjs,gulp,angularjs-service,angularjs-factory,angularjs-http
At a grance, I couldn't find anything wrong in your code. However interceptor assumes to receive return value, therefore If you don't return any values as your sample code, it is possible to cause unexpected problems. Try this code below. angular.module('qrWebapp').factory('errorInterceptor', function($q){ var errorInterceptor = { response: function(res) { console.log(res.status);...
javascript,ajax,angularjs,angularjs-directive,angularjs-factory
Fixed it for you: http://plnkr.co/edit/rrowocPucUFAN6Ii1COf?p=preview You were using 'data' both in the factory, and as a variable name within the success callback. This is the offending section: myFactory.$inject = ['$http']; function myFactory($http) { var data = {}; data.blueData = 0; data.redData = 0; data.changeBlueData = function () { $http.get('http://httpbin.org/ip'). success(function(response,...
angularjs,angularjs-scope,angularjs-factory
Service should be directly depends on scope, they could be indirectly depend on each other. If you pass $scope to the service it will become tightly couple to that specific controller. Like in your case you only pass accountnumber, then service will make an required operation like doing an...
json,angularjs,angularjs-service,angularjs-factory
example of service - resolve the success with the data you want app.service('Data', ['$http', 'apiKeys', function($http, apiKeys){ var googleDocs = 'https://spreadsheets.google.com/feeds/list/'; this.news =function(){ return $http.get(googleDocs + apiKeys.googleDoc +'/1/public/values? alt=json', {cache: true}) .then(function(data){ return data.feed.entry.length; }); } }]); the controller - since you already resolved the data in service hence.. app.controller('homeCt',...
javascript,angularjs,angularjs-factory
this inside success callback function is different app.factory('Config', ['$http', function($http) { return { conf: null, init: function () { var self = this; if (this.conf === null) { $http.get('/config') .success(function (data) { self.conf = data; }); } } } } ]); ...
javascript,angularjs,angularjs-factory
Regarding the list function When the CountryListCtrl controller is instantiated, the countries service (which is an object) is being passed as an argument. Then the countries.list function (defined within countries service obviously) is being called and passed a callback function. The countries.list function makes a GET request, and if successful...
javascript,angularjs,undefined,angularjs-controller,angularjs-factory
Is my error, i call in another controller User.get();, My problem is in time app.controller('Controller', function ($scope, User) { $scope.user = User; setTimeout(function(){ console.log(user.data); // i have data }, 5000); }); ...
angularjs,parse.com,angularjs-factory,angularjs-ui-router,angularjs-promise
You should inject currentRestaurantService dependancy first before using it in resolve currentRestaurant function. Code .state('dashboard.sales', { url: '/sales', templateUrl: './app/dashboard/partials/sales/sales.html', controller: 'DashboardSalesCtrl', resolve: { currentRestaurant: function(currentRestaurantService) { //added dependency in function return currentRestaurantService.getCurrentRestaurant(); } } }) ...
angularjs,angularjs-resource,angularjs-factory
Check out the docs. About halfway down: The action methods on the class object or instance object can be invoked with the following parameters: HTTP GET "class" actions: Resource.action([parameters], [success], [error]) non-GET "class" actions: Resource.action([parameters], postData, [success], [error]) non-GET instance actions: instance.$action([parameters], [success], [error]) And an example from their page:...
javascript,angularjs,angularjs-factory
You haven't really explained what you did to fix this issue, so I'll explain it. Here, you are trying to call xmlService.saveCharacter.success(): xmlService.saveCharacter.success(function(data){ console.log(data); }); But xmlService.saveCharacter is a function. It has no success property; success is undefined. So this gives the error you were seeing. You need to call...
angularjs,asp.net-mvc-4,angularjs-controller,angularjs-factory
per the comments, /register was referencing the wrong controller. changed this: .when('/register', { templateUrl: 'Account/Register', controller : 'LoginController' }); to this: .when('/register', { templateUrl: 'Account/Register', controller : 'RegisterController' }); ...
angularjs,angularjs-service,angularjs-factory
Why you are passing serviceListService in $scope function? You don't need it since it is declared in the whole controller. Just try this: $scope.doRefresh = function($scope) { serviceListService.getFromServer($scope); //<-this is where i am getting the error //$scope.$broadcast('scroll.refreshComplete'); }; ...
angularjs,angularjs-controller,angularjs-factory
Your solution works more or less like this: app.factory('mixinBaseController', function(myService) { return function (scope, variable) { angular.extend(scope, { variable: variable; method: function() { myService.doSomething(variable); } }); }; }) .controller("ChildController1", function($scope, mixinBaseController) { mixinBaseController($scope, "variable1"); }) .controller("ChildController2", function($scope, mixinBaseController) { mixinBaseController($scope, "variable2"); }); Can you see? By your .call($scope, ...) is...
javascript,angularjs,angularjs-factory,dynamic-variables
You should consider storing all of your factories on an object: var factories = { factoryA: { method: function() {} }, factoryB: { method: function() {} }, }; var factory = 'factoryA'; factories[factory].method(); ...
javascript,angularjs,angularjs-service,angularjs-factory
Service vs Factory The difference between factory and service is just like the difference between a function and an object Factory Provider Gives us the function's return value ie. You just create an object, add properties to it, then return that same object.When you pass this service into your controller,...
angularjs,angularjs-controller,angularjs-factory
The error message you are getting appears to be correct. $scope.lines does not exist in your factory but in your controller. So what you might have intended to do would be to pass that value in from the controller to the factory like the below function in controller config.updateLines($scope.lines); function...
javascript,angularjs,unit-testing,karma-jasmine,angularjs-factory
I ended up havinmg to include jquery whic the links from the error told me to do this. But I was still getting an error. Make sure you alwasy load the library dependencies in the same order as your app does.
javascript,angularjs,angularjs-service,angularjs-factory
You can call angular.module('app').run(function(){...}). So you will not need a global variable anymore. Example: angular.module('app').run(['mysevice', srvc.run.bind(srvc)]); ...
javascript,angularjs,dependency-injection,jwt,angularjs-factory
Inject all the required dependency in your app module. That what you were injecting new module while declaring factory. Code var webapp = angular.module('myAppName',['angular-jwt']); webapp.factory('Auth',['$http', 'API_URL', '$window', '$location', 'jwtHelper', function($http, API_URL, $window, $location, jwtHelper ) { //your c0de here }]); ...
javascript,angularjs,ionic-framework,angular-services,angularjs-factory
See this working fiddle , You are treating service as if it was a controller, never inject a $scope into service, its not there var myApp = angular.module('myApp',['myapp.services','myapp.controllers']); angular.module('myapp.controllers', []) .controller('StreamCtrl', ['$scope', 'StreamService', function($scope, StreamService) { $scope.playlists = [1,2,3,4]; }]); angular.module('myapp.services', []).factory('StreamService', function() { var self = { 'fetching' :...
javascript,angularjs,angularjs-directive,angularjs-service,angularjs-factory
I hacked together a basic example of notifying the directive of an update via callback based on what type of tag it's interested in observing. I put in three text fields, the identifier text field is the one that actually matters. First the markup, which is just an empty directive,...
angularjs,promise,angularjs-service,angular-promise,angularjs-factory
Basically you need to implement a promise chain as look into your code looks like you are carrying getCliente() promise to getDetCliente method. In that case you need to use .then function instead of using .success & .error which doesn't allow you to continue promise chain. There after from getDetCliente...
javascript,angularjs,angularjs-resource,angularjs-factory
You do not call any method of resource you only initialize it. Try this: factories.factory('FooFactory', function ($resource) { var foo = null; return { query: function () { foo = $resource(baseUrl + '/someUrl/:query', {}, { query: { method: 'GET', isArray: true } }).query(); }, getFoo: function () { return foo;...
javascript,angularjs,prototype,angularjs-service,angularjs-factory
Try this approach: // define the TagsObject constructor function var TagsObject = function(name, tag) { this.name = name; this.tags = [tag]; return this; }; The best way to initialize an array is to include the elements inside the brackets [ 1 , 2 , 3 ] But in case you...
angularjs,firebase,ionic-framework,angularjs-factory
I think you are facing some asynchronous data loading issue. I am not sure about the $firebase, but u just try angular.module('starter.services', ['firebase']) .factory('OtherFriends', ['$firebase', function ($firebase) { var ref = new Firebase("https://example1234.firebaseio.com/"); var sync = $firebase(ref); return { all: function() { return sync.$asArray(); }, get: function(friendId) { // Simple...
angularjs,angularjs-scope,angularjs-factory
You need to return the promise from the $http call in the service, and in your controller add a.then handler to the service method call. In the then handler update your scope property FTW
angularjs,angularjs-service,q,angular-promise,angularjs-factory
Here are one working solution: http://jsfiddle.net/gxbwk6dk/9/ You are returning same object, I have modified when you have a hit: if (obj === searchEle) { deferred = $q.defer(); deferred.resolve(jsObject[obj]); } ...
javascript,angularjs,http,angularjs-factory
The $http call is an ajax asynchronous call which means you'll need to send the result through a callback. This may help: Here's the factory: myNameSpace.factory('simpleFactory', function ($http) { var factory = {}; factory.getCustomers = function (callback) { $http.jsonp('http://URL&callback=JSON_CALLBACK').success(callback); } return factory; }); Here's how to use it: myNameSpace.controller('DetailsController', function...
angularjs,angularjs-scope,angularjs-factory
First, let's get the terminology right. .factory is a method to register a function that generates an instance of the service - hence "factory". What it generates, though, is a singleton service instance. So, the service you create would be more properly named as FireSvc (as opposed to FireFactory), whereas...
javascript,angularjs,angularjs-factory,angularjs-module
This is what I would do: On Factory One angular.module('sampleApp') .factory('factory1', function() { var factory1 = {}; factory1.method1 = function () { return true; }; factory1.method2 = function () { return "hello"; }; return factory1; } ); On Factory Two angular.module('sampleApp') .factory('factory2', ['factory1', function(factory1) { var factory2 = {}; factory2.method3...
angularjs,angularjs-service,angular-promise,angularjs-factory
You can modify getByid method like this. this.getById = function(id){ var def = $q.defer(); deferred.promise.then(function(data){ //find the matching list for (var i = 0;i <data.data.listings.length;i++) { if (data.data.listings[i].id == id) { def.resolve(data.data.listings[i]); return; } } //Reject the promise here because we didn't find the matching id def.reject(); }); return def;...
javascript,angularjs,unit-testing,angularjs-factory
I believe you should be using Jasmine 2.0's done() to signal that the test has finished. If you don't then the async tests will not finish.
javascript,angularjs,angular-services,angularjs-factory
Is this what you are looking for? var currentUserSrvc = function() { // some logic on how to save the user to localStorage return { get user() {return localStorage.user;}, set setUser(user) {localStorage.user = user} }; }; angular.module('app').factory('currentUser', currentUserSrvc); This is how you use getters and setters in javascript: So you...
angularjs,dependency-injection,angularjs-service,angularjs-factory
Service vs Factory The difference between factory and service is just like the difference between a function and an object Factory Provider Gives us the function's return value ie. You just create an object, add properties to it, then return that same object.When you pass this service into your controller,...
javascript,angularjs,ionic-framework,angularjs-factory,angularjs-http
You post syntax should be posts = response.data.items return $http.get("https://www.example.com/posts?format=json").then(function(response){ posts = response.data.items; //items here return posts; }); ...
angularjs,angularjs-scope,angularjs-factory
I think you will find that the contactListCtrl is not being setup again when you navigate back to it (after a delete). I believe this is because Ionic caches views for you. What you need to do is listen to $ionicView.beforeEnter event and load your contacts list into your ContactListCtrl...
The this.authenticated in authenticator.attempt will return before the asynchronous call from $resource has completed. You will need to wait for the promise to be resolved before returning from the factory, and before receiving in the controller. Something like this should hopefully work: Factory: authenticator.attempt = function(email, password){ var current =...
javascript,angularjs,angularjs-scope,angularjs-service,angularjs-factory
You are messing with Dependency injection array, that should follow correct order of dependency when you are using it in a function. Code angular.module('appcontrollers', []).controller('LoginController', ['$rootScope', '$scope', '$http', '$location', '$localStorage', 'loginService', function ($rootScope, $scope, $http, $location, $localStorage, loginService) { ...
angularjs,factory,angularjs-factory
Your assumptions are wrong. Whatever the way you choose to create a service, it's always a singleton. Angular will call your service constructor, or your service factory, or your provider function only once, and reuse the created object.
javascript,angularjs,factory,angularjs-controller,angularjs-factory
You are not injecting it properly: ['$scope', DataFactory, function($scope){ should be ['$scope', 'DataFactory', function($scope, DataFactory){ Not to mention that you are missing a ] in your DataFactory return value....
angularjs,angularjs-scope,angularjs-factory
It seems that the code you provided working fine and the problem is somewhere else, probably in cms controller or in confirm.html template. I've made a plunker with your factory where you can see it live. index.html <div ng-controller="ctrl1"> <button ng-click="msg.confirmSave()">confirm save</button> <span ng-if="msg.getResponse() !== undefined">Response: {{msg.getResponse()}}</span> </div> confirm.html <h1>{{msg.text}}</h1>...
angularjs,asynchronous,angularjs-service,angularjs-controller,angularjs-factory
You must be getting .then of undefined error Because you missed to return promise from service method. Service var MessageFactory = { getCast: function() { var request = { method: "GET", url: spHostUrl + "/_api/web/Lists/getByTitle('" + listTitle + "')/items?$select=AuthorId,Author/Name,Author/Title,Type_x0020_message,Title,Modified,Body,Expires,Attachments&$expand=Author/Id", headers: { "Content-Type": "application/json;odata=verbose", "Accept": "application/json;odata=verbose" } }; return $http(request)...
angularjs,dependency-injection,angularjs-service,angularjs-factory,angularjs-provider
How about pseudo inheritance with angular.extend /* define a "base" controller with shared functionality */ .controller('baseCtrl', ['$scope', .. function($scope, ...) { $scope.getMinutes = function(minutes) { var duration = moment.duration(minutes, 'm'); return duration.minutes(); }; .controller('C2gCtrl', ['$controller', '$scope', ... function($controller, $scope, ...) { // copies the functionality from baseCtrl to this controller...
angularjs,angularjs-service,angularjs-factory
If you have an error such as this: Error: [$injector:unpr] Unknown provider: ResultsServiceProvider <- ResultsService <- ResultsController it usually mean one of those things: you've either misspelled the ResultsService name when creating (declaring) it or you haven't insterted a script tag pointing to the file that contains the service in...