FAQ Database Discussion Community


AngularJS: Refresh angular scope outside of ng-view

javascript,angularjs,angularjs-service
OK, so I have a basic login page that when the user logs in I want to then display more details on the navbar at the top of the screen. When they click logout, this then goes away. This is working (in a way) however to get the navbar to...

How to repurpose my directive here to work in 2 different scopes?

javascript,angularjs,angularjs-directive,angularjs-service
http://plnkr.co/edit/39FGMocKB5GtQWnI1TFw?p=preview I have sidebar which contains a list of tags, when you click on a tag I use the TagDetailsFactory to send a tag into the scope of the view controller. Everything works great except for when you hover over a tag in the TagDetailsFactory scope. The tagDetails template does...

AngularFire $createUser 's promise doesn't return an object containing user data

javascript,angularjs,firebase,angularjs-service,angularfire
According to the documentation the $createUser function, "... returns a promise that is resolved with an object containing user data about the created user" https://www.firebase.com/docs/web/libraries/angular/api.html#angularfire-users-and-authentication-createusercredentials When I use the function (see code below), I can register the user sucessfully but when I read the variable that should contain the UID,...

Returned variable from service not updated

angularjs,angularjs-service
I am following this style to write my angular code: https://github.com/johnpapa/angularjs-styleguide Basically it says to do this with your services: /* recommended */ function dataService() { var someValue = ''; var service = { someValue: someValue, validate: validate }; return service; function validate() { /* */ }; } Which is...

Angular watching Service properties

javascript,angularjs,angularjs-service,angularjs-controller
Take the following plunk as an example: http://plnkr.co/edit/vKFevXhhSprzFvesc6bG?p=preview var app = angular.module('plunker', []); app.service('SomeService', ['$rootScope', function ($rootScope) { var service = { value: false } return service; }]); app.controller('MainCtrl', ['$scope', 'SomeService', function($scope, SomeService) { $scope.value = SomeService.value; //$scope.$watch(function () { return SomeService.value; }, function (data) { $scope.value = data; });...

Angular service watching for json property change, copying value to other property

angularjs,angularjs-service
Given json data provided by an angular service: { "editableData": { "test": { "value": "Never gonna give you up" } }, "hiddenData": { "test": { "value": "Never gonna let you down" } } } ... I want to let the user modify editableData.test.value, but continuously synchronise that value across to...

How to structure an Angular service so it can handle asynchronous calls?

angularjs,asynchronous,promise,angularjs-service,angular-promise
In my Angular application, I have two controllers which both need access to the same data. Toward that end, I've created a service which will be responsible for holding and providing access to that data: angular.module("SomeModule").factory( "SomeService", function( $http ) { var svc = {}; var data = {}; //...

Initialize Angular Service (factory) when application start

javascript,angularjs,angularjs-service,angularjs-factory
In my Angular application I adding tracing functionality, which should work as separate plugin, so if script included into HTML Angular should create service and initialize (run) it. Plugin is service because it has mandatory dependency on $rootScope. For implementation I select to use Angular factory, like (code is in...

Why AngularJS service factory is returning undefined

angularjs,angularjs-service
I am having a service as follows services.js var CalculatorService = angular.module('CalculatorService', []) CalculatorService.service('Calculator', function () { this.square = function (a) { return a*a}; }); CalculatorService.factory('StringManipulation', function () { var r= function reverse(s) { var o = ''; for (var i = s.length - 1; i >= 0; i--) o...

Cannot instantiate service although it is loaded

angularjs,angularjs-service
This is the main module: (function() { "use strict"; angular .module('wda', [ /* Angular modules */ 'ngRoute', /* 3rd-party modules */ 'ui.bootstrap', /* Feature areas */ 'wda.overview', /* Shared resources */ 'websiteService' ]) .config(function($routeProvider) { $routeProvider .otherwise({ redirectTo: '/overview' }); }); }()); This is a service I'd like to use...

Working with APIs in AngularJS

angularjs,api,angularjs-directive,angularjs-service,angularjs-http
I'm trying to create a layout that displays 'channel' data for multiple 'users'. The API I'm using requires one to query first to get a list of username and then another query for each user to get the channel information. I gave it my best shot but ended up breaking...

AngularJS passing lastTime to a service to display only recent posts

angularjs,angularjs-scope,angularjs-service,angularjs-controller
I am not sure if I am going about this the right way but what I want to achieve is a Twitter feed like effect. I have a Statuses page, on the first page load it will get all the statuses and after then it will only display the updates...

Angular service variable not updated in the view

javascript,angularjs,angularjs-directive,angularjs-service
I have the following service: app.service('Cart', function() { this.data = []; this.addFont = function(font) { return this.data.push(font) }; this.removeFont = function(i) { return this.data.splice(i, 1); }; this.count = function() { return this.data.length; }; }); And the following directive, that displays a cart icon with the number of items in it:...

How to asynchronously populate a $scope variable in AngularJS?

javascript,angularjs,asynchronous,angularjs-scope,angularjs-service
I have the following service: app.service('Library', ['$http', function($http) { this.fonts = []; this.families = []; // ... some common CRUD functions here ... // Returns the font list this.getFonts = function() { if(_.isEmpty(this.fonts)) this.updateFonts(); return this.fonts; }; // Returns the family list this.getFamilies = function() { if(_.isEmpty(this.families)) this.updateFamilies(); return this.families;...

Angularjs service variables not updating properly

angularjs,angularjs-scope,angularjs-service
I'm learning angular and trying to get an understanding on how services and scope work together. I have the following plnkr which is an off/on canvas menu (http://plnkr.co/edit/wP1Fu6vlJiopJi5AzkQt). I've attempted to split controllers. I define boolean variables called navLeft & navRight in the service call navState. I use the left...

Angular - Using $http Service in Controller Function

angularjs,angularjs-service
folks-- so in my continuing Angular adventures, I've run into an issue where $http.get is working for me, but $http.post is not. It's obvivously an issue of scope (i.e., my controller function sees '$http', but one of its functions cannot. Here's my code so far: var app = angular.module('docManager', []);...

Why am I getting ngRepeat:dupes when sending data from an Array into a differently named Array?

javascript,angularjs,angularjs-ng-repeat,angularjs-service
Error: ngRepeat:dupes Duplicate Key in Repeater http://plnkr.co/edit/hZtIXkPM7dhpf4P7rd6W?p=preview I have an array which ng-repeats a list of tags on the page. Next I have an ng-click which sends the tag data into the scope of another controller whois job it is to display those selected tags in another list. It's easier...

Communicating between controllers in AngularJs

angularjs,angularjs-service,angularjs-controller
I have a simple question: what's the best ('cleanest', 'scaleable') path one should go when it comes to interact between (let's say) two controllers. Would that be to define a service and watch that service's return-value in order to react? I setup a simple example here, where I watch the...

How to make data available in all scopes in Angularjs

javascript,html,angularjs,angularjs-scope,angularjs-service
I wish to fetch data from the server-side using $http and and make it available to the all routes and controllers in my app. Javascript code sample myApp.factory('menuService', function($http){ $http.get('/pages').success(function(data){ return data; //list of pages }); }); myApp.run(function($rootScope, menuService){ $rootScope.menu = menuService; }); HTML code sample <ul > <li ng-repeat="page...

unable to set or get a method from service throwing not a function issue in angularjs

angularjs,angularjs-service
In my service: myApp.service('settingsService', [ function() { var id; this.setObjectId = function (data) { id = data; } this.getObjectId = function () { return id; } }]); From my directive: Note: Already injected that service. settingsService.setObjectId(4); am setting like this But am getting the following script error: TypeError: undefined is...

AngularJS: Uncaught ReferenceError: $rootScope is not defined in run

javascript,angularjs,firebase,angularjs-service,angularfire
I am trying to route all unauthorized traffic to the login page, and am using angularfire to authenticate. Here's all the relevant code. I know most of it is broken, but I'd like to get past this first. The problematic code is: App.js app.run(['$rootScope', '$location', 'AuthenticatorService', function ($rootScope, $location, AuthenticatorService)...

Injecting a Angular service into controller results in $injector:unpr error (using AngularBooter)

angularjs,angularjs-service,angularjs-controller
I am using the AngularBooter for Angular in my app. Here is my code: emp.boot(); emp.services.SocialService = ['$http', '$q', function ($http, $q) { var deferred = $q.defer(); $http.get('/api/feed').then(function (data) { deferred.resolve(data); }); this.getStatuses = function () { return deferred.promise; } }]; emp.controllers.StatusesController = ['$scope','SocialService', '$interval', function($scope, SocialService, $interval) { var...

I get custom method undefined error when I encapsulate $http service in custom service

angularjs,angularjs-service
I am new to AngularJS and I am trying to create custom service to encapsulate $http service. I have tried debugging but am not able to fix this. Could you please tell what am I doing wrong here. The function in the custom service returns a promise. I think the...

How To Reference an Agular Services's Variable from a Promise then function inside the Service?

javascript,angularjs,angularjs-service
I am trying to use a $http call inside an Angular service where the returned promise is handled with a then function. Inside the then function I want to be able to update a variable of the service, however I cant seem to figure how to do this. As you...

Calling additional service functions after a resolved promise in Angular

javascript,angularjs,angularjs-scope,angularjs-service,angularjs-promise
In Angular I have a service to access the google contacts api, then store all my contacts into variable (StorageVar) to be analyzed by other functions in the service. Should I call one of the analysis functions before getting the data from the API, I want to call the getAPI...

Angularjs Cannot get the correct data from a service in a controller

angularjs,cordova,ionic-framework,angularjs-service,angularjs-controller
I try to build a mobile app with Ionic/Angular/Cordova, and I have some problems with a service :) My code looks like this : SERVICE: 'use strict'; angular.module('MyDemoApp.services').service('ImageService', function($cordovaCamera, $cordovaFile) { // 1 //$scope.images = []; this.addImage = function (method){ var imageDetails ={'name':'', 'src':'' }; // 2 // Set the...

Broadcast different controllers in AngularJS

angularjs,angularjs-scope,broadcast,angularjs-service
I am developing a permission system for my app using a factory that looks like this: angular.module('ecosystemServices', []) .factory('Guard', function($http, $rootScope) { var permissions = []; return { ready: function() { if (permissions.length == 0) { $http.get('/api/users/own-permissions') .success(function(data){ permissions = data.user_permissions; $rootScope.$broadcast('permissionsReady', 1); }); } else { $rootScope.$broadcast('permissionsReady', 1); }...

access angularjs deferred promise from new template

angularjs,angularjs-service,angular-promise,angularjs-factory
I'm new to angular and LOVE it...coming from a 10 yr PHP background there is a lot of new terms for me. Here is what I would like to-do, not sure if it's possible, if yes, not sure how. I have created a list of properties and that part works...

AngularJS service gets the data, but doesn`t return it to the controller?

javascript,angularjs,angularjs-service,angular-promise
scope.membersWarnings in controller is always empty, but in service it gets the data from the server. Somehow my data from the server is lost between callback of get function in service and controller. Controller: AndreaApp.controller('MemberDetailController', ['$scope', '$rootScope','$http','$location','$routeParams','MemberService','MemberGroupsService','ArrivalsService','WarningsService','NotificationsService',function (scope,rootScope,...

How to send updated object from Service into Directive Controller function the Angular way?

javascript,angularjs,angularjs-directive,angularjs-service,angularjs-factory
I know I'm missing the AngularJS way to do this correctly. On mouseover in my tagsPanel's view I capture the tag object and first send it into my tagsPanel controller: tagsPanel.html <ul> <li ng-repeat="(k, m) in tags" ng-mouseover="hoverTag(m)" ng-mouseleave="leaveTag(m)"> <div class="tag">{{m.term}}</div> <tags-hover ng-model="m"></tags-hover> </li> </ul> tagsPanel Controller: vs.hoverTag = function(tagObj)...

Updating directive based on change in service value AngularJS

javascript,angularjs,angularjs-service,angularjs-controller
I have a basic app currently that has a list of names in a sidebar nav populated from a json call to my server. When the user clicks on a name in the sidebar, it updates the nameService to the name clicked on by the user. When the nameService gets...

Controllers and directives, precedence

angularjs,angularjs-directive,angularjs-service,angularjs-controller
I've been with Angularjs a few days and I'm struggling with a few aspects of it. I'll do my best to try and explain what the issue is, and I'd really appreciate any help anyone can give me about it. My situation (simplified) is this: I have a service which...

Initialize a non injected angular service

angularjs,angularjs-service
I have a angular service that in its constructor listens to an event on the $rootscope. This service is not injected anywhere in the application and therefore it is not initialized. To solve that we're just injecting it and not using it in another service, just to get it to...

HTTP Get in AngularJs Could not located the Json file

json,angularjs,angularjs-service
I have tried several times with the following code to get the json data. var todoApp = angular.module("todoApp", []); todoApp.run(function($http) { $http.get('todo.json').success(function (data) { model.items = data; }); }); here todo.json file is located on the root of the project....what wrong i am doing?...

Angular-Fullstack + UI router isn't routing properly

angularjs,angular-ui-router,angularjs-service
I'm attempting to route my application using UIrouter with the current yeoman-fullstack generator without mongoDB. In this example of my issue, everything is default to test and make sure the UI-router is working properly. Mainly because I'm not understanding and missing something silly and noobish here, so I apologize. https://github.com/DaftMonk/generator-angular-fullstack...

set/get data in service from controllers

javascript,angularjs,angularjs-service,angularjs-controller
Just trying to figure out how some of this works so I want to input a number in a view then have the controller set that data in the service and switch views. Then the controller for the next view should get that number from the same service and eventually...

success and error function in the controller for a service

javascript,angularjs,angularjs-service,angularjs-http,angularjs-promise
I have the following code in a service and I am calling fetchData function from the controller. Service app.service("geturl", function($http) { urllist = []; geturl.fetchData = function() { var data = []; for (i = 0; i < urllist.length; i++) { (function(index) { return $http.get(geturl.urllist[index], { timeout: 8000 }) .then(function(response)...

How to observe or watch an input attribute change in an AngularJS Service?

javascript,jquery,angularjs,angularjs-service,angular-services
I have a radio button in my UI that has an ngModel and it enable/disable another input through ngDisabled. I want to observer/watch/trigger when an input element become enabled/disabled and it has to be done in an Angular Service. I simply can't find how to do that. Here is how...

How to send a valid crsf token with angularjs $post service and symfony2

ajax,symfony-forms,angularjs-service,csrf-protection,angular-http
I think I read enough topics for posting this question... and I really want to know why my submission using ajax is invalid (The CSRF token is invalid. Please try to resubmit the form). This is how I send my form data and the csrf token. <form name="ReviewForm" ng-init="formData =...

How to call other functions of same services in ionic (angular.js)

javascript,angularjs,ionic-framework,ionic,angularjs-service
I am working on a mobile app using ionic framework. I have created a common Utility services like this .service('CommonUtilityService', function($q) { return { parseJsonDate:function(jsonDate){ var offset = new Date().getTimezoneOffset() * 60000; var parts = /\/Date\((-?\d+)([+-]\d{2})?(\d{2})?.*/.exec(jsonDate); if (parts[2] == undefined) parts[2] = 0; if (parts[3] == undefined) parts[3] = 0;...

AngularJS Factory JSON Array with HTTP GET

json,angularjs,angularjs-service,angularjs-factory
I'm developing my first AngularJS app using the Google Docs API to pass it JSON data. This is an example of the factory I'm using: app.factory('Data', ['$http', 'apiKeys', function($http, apiKeys){ var googleDocs = 'https://spreadsheets.google.com/feeds/list/'; return { news:function () { return $http.get(googleDocs + apiKeys.googleDoc +'/1/public/values?alt=json', {cache: true}); }, updates:function () {...

Unable to access $http response data in Angular JS factory

angularjs,angularjs-scope,angularjs-service
I am trying to save $http response data in a variable inside angularJS factory. But I could not access the response outside the http method. It is showing undefined. I checked this link Injecting $scope into an angular service function() Please let me know how to handle this. Below is...

Angular “Unkown Provider” - how to use a factory within routeProvider configuration?

angularjs,angularjs-service,ngroute,angularjs-provider
While playing around with Angular I try to understand better how to use factory, services, constants, routing and other core concepts. So I build a simple demo app with node, express, jade and angular. Now I would like to use a value inside the routeProvider configuration. I created a constant,...

angular inside the service string argument converted to array

javascript,angularjs,angularjs-scope,angularjs-service
I have the following angular structure //html <input type="text" model="name"> <div ng-if="!validateMyname(name)"></div> //controller
 $scope.validateMyname = function(arg){ console.log(arg); //LINE 1 return myService.validateXY(arguments); } //service angular.module('services').factory('myService', function () { myService.validateXY = function(a){ console.log(a); //LINE 2
 }
 return myService; }): I can see the string that I have input in LINE 1. but...

Angular Service for data between controllers

angularjs,angularjs-service
I have a page with a main controller and a nested controller for showing details about a product. I want to use a a service in angular to call the server, retrieve a data object and hold that data object. The main controller will call the service to fetch the...

$http returns promise instead data

angularjs,angularjs-service
I started with AngularJS yesterday, so I'm sure I'm being extremely dumb on this question, but here we go. This is my service. angular.module('UserService', ['ngResource']) .factory('User', ['$resource', '$http', function($resource, $http){ User = {}; User.login = function (){ var url = 'http://example.com/api/user/login'; loginInfo = $http({ method: 'POST', url: url, data: "user=user&pass=imagethereisahugepasshere",...

Update angular service variable on window resize

javascript,angularjs,resize,angularjs-service
I am trying to update a service variable on resize. The update doesn't seem to be registered by the controller, even though I'm using angular.element to bind the event. The initial setDevice() works, but on resize when I log the Device service on window resize from the controller there is...

Angular JSONP Factory call not working, however it does work in controller

javascript,angularjs,angularjs-service
I have looked at every post on SO related to this issue but still cannot find the answer. This response appeared to be the most promising but I didn't understand the answer, and it appears the person who asked did not either. What am I trying to do? Make a...

Set a return value to a scope vaiable in Angular.js

angularjs,angularjs-scope,angularjs-service
I'm new to anguar.js, I'm stuck with a problem. I need to set a variable with the return value from a service a and then access it outside the. Here is my code, fetchService.store_closing_time($scope.currentStore.id, moment(new Date()).format('YYYY-MM-DD')) .then (result) -> $scope.changedStoreCloseTime = result.close_time console.log "############# display inside##########" console.log $scope.changedStoreCloseTime , (result)...

How to make a prototype out of 2 identical controllers in angularjs?

angularjs,dependency-injection,angularjs-service,angularjs-factory,angularjs-provider
In my app I have 2 almost identical controllers. A lot of functions are the same, so I'd like to prototype them. This is Controller #1: c2gcontroller.js angular.module('c2gyoApp') .controller('C2gCtrl', function($scope) { // some unique stuff $scope.feeDay = 59; ... // the identical functions $scope.getMinutes = function(minutes) { var duration =...

Unit test with promises: How to mock $q or know deferred has been called

angularjs,unit-testing,jasmine,angularjs-service
I have a service that are using promises. Here is a simplified example of my service: angular.module('myService').service('popup', [ '$q', function( $q ) { this.alert = function(myValue) { var deferred = $q.defer(); if (myValue = 0) { deferred.resolve('myValue is null'); } else { deferred.reject('myValue isn\'t null'); } return deferred.promise; } }]);...

Is this a “Deferred Antipattern”?

angularjs,angularjs-directive,angularjs-service,angular-promise
I'm finding it hard to understand the "deferred antipattern". I think I understand it in principal but I haven't seen a super simple example of what a service, with a differed promise and one with antipattern, so I figured I'd try and make my own but seeing as how I'm...

Communicate to another, specific controller

angularjs,angularjs-service,angularjs-controller
I'm a bit lost... I'm quite new to Angular and writing a small app for practicing. I've two views with a table and each view has it's own controller. The tables use some equal functions, like edit, save... To avoid duplicate code I've put these functions in a seperate controller....

AngularJS $httpProvider Error

angularjs,gulp,angularjs-service,angularjs-factory,angularjs-http
I'm writing a web application in AngularJS with Django API endpoints. When I want to perform a JSON call to this endpoints, I want to catch possible errors (such as 404 not found error). For this, I'm using $httpProvider. But when I run my application (using gulp), in the console,...

Angular service for a library that dynamically generates objects with async methods

angularjs,angularjs-service
I want to write an Angular service wrapper for the following non-Angular library with classical async success/error handlers, so that it would integrate nicely into Angular app using promises and being Angular-aware. In a typically case, this would just be a matter of writing a facade that wraps the async...

How to keep entered data of page1 after navigating back from page2 in AngularJS

html,angularjs,angularjs-service,angularjs-routing,angularjs-controller
I have three pages with routing. If I entered some input and getting some result on first page, next I navigated to second page and finally I came back from second page to first page. Then I want to see the data what I entered previously and result also. Here...

How do I set the value in my angularjs service?

angularjs,angularjs-service
I have created a service I want to use to set the value between controllers. I am using ng-model. Before my service I had this in my html: <div class="col col-25"> <a class="input" data-ng-keypad-input="numeric" tabindex="15" data-ng-model="fields.widthDefault" ng-change="updateROIWidths()">{{fields.widthDefault}}</a> </div> my fields were defined as such: $scope.fields = { widthDefault : 0...

How to append customized service into angular ng module directly

angularjs,angularjs-service,angularjs-module
I tried to add a custom service into the ng module directly 'use strict'; angular .module("ng") .service('getAQueryParameterByName', ['', function(){ console.log("getAQueryParameterByName service active"); this.getParameter = function(name){ console.log("getParameter!"); } }]); As a result, when I try to run the service by doing getAQueryParameterByName.getParameter(var) I encountered error of ReferenceError: getAQueryParameterByName is not defined...

ng-change function gets run on page load before data loads?

angularjs,angularjs-service
One of my controller functions gets run before my data loads. The html: <div ng-show="item.name"> <input ng-change="doChange()" ng-model="item.name"> </div> My controller: $scope.item = { name: 'bob' }; $scope.other = {}; $scope.doChange = function() { $scope.item = $scope.other['test'].name } // load the data now! MyService.getData().success(function(newdata) { $scope.item = newdata.item; $scope.other =...

AngularJs factory function undefined in controller

angularjs,asynchronous,angularjs-service,angularjs-controller,angularjs-factory
I used to make it work the exact same way before, and it's driving me crazy. I want to perform a $http GET call into a factory and then get back the result into the controller, to be processed. The factory (don't pay attention to the madness of the request...

Convert factory to service in Angularjs

angularjs,angularjs-service,angular-services
I'm using $resource to fetch a json from server which is working fine: topicServices.factory('Topic', ['$resource', function($resource){ return $resource('http://localhost/topic_api_response.json', {}, { fetchData: {method:'GET', isArray:true} }); }]); However, now I want to convert this factory to a service by doing something like this: topicServices.service('Topic', ['$resource', function($resource) { this.fetchData = function() { var...

need to handle session time out using promises ($q) in Angularjs application

jquery,ajax,angularjs,angularjs-service,angular-promise
I am trying to convert my existing jquery Ajax request to use Angularjs Promises. I am not able to figure how to include fail condition in my promises. Except that remaining things are working fine. Earlier I had my jquery Ajax call as shown below. Here when I make an...

delay in calling the angularjs service [closed]

angularjs,angularjs-service
I've a service in which i'm making a POST call through $http. I'm calling this method from a different function in a controller, I've several lines of code written in the function of my controller which I want to execute after the service call, though I'm calling the function in...

Can't attach angularjs service to controller

angularjs,angularjs-service
I'm getting this error when I try to attach a service to a controller: [$injector:unpr] ... webSocketServiceProvider <- webSocketService <- videoMenuCtrl I have a plunker defined with a fairly minimal setup that reproduces the problem: http://plnkr.co/edit/ptaIaOhzOIG1mSi4bPyF?p=preview Here are the main culprit files: index.html: <!doctype html> <html> <head> <meta charset="utf-8"> <title>title</title>...

Call controller function from service in angularjs

angularjs,angularjs-service
I am using socket.io to enable chat in my app and i am using a service SocketService to perform all the socket stuff. When a message came then i want to trigger a function of a controller from the service SocketService to make some changes in the UI. So i...

How to make a service object that doesn't share its values with controllers that consume it

angularjs,angularjs-service,angularjs-factory,angularjs-provider
Let's suppose I create a factory, service, or provider object like so myApp.factory('myService', function() { return { counter: 0, increment: function() { console.log('counter: ' + (this.counter++)) } }; }); And suppose I have a controller that depends on it myApp.controller('myCtrl', function(myService) { $scope.incr = function() { myService.increment(); }; } And...

Angular - TypeError: XX is not a function

javascript,angularjs,angularjs-scope,angularjs-service,angularjs-factory
Maybe I'm missing some kind of property, but I'm follow this project and I'm getting this error in my controller. TypeError: loginService.signin is not a function This is my controller.js angular.module('appcontrollers', []).controller('LoginController', ['$rootScope', '$scope', '$http', '$location', '$localStorage', 'loginService', function ($rootScope, $scope, $http, loginService) { $scope.signin = function() { console.log("username: "...

How to push objects into array inside of a JavaScript Prototype?

javascript,angularjs,prototype,angularjs-service,angularjs-factory
I have an Angular Factory whose job is to save special objects and retrieve them later. (Used to save the users workflow when he switches views). Basically I need to save objects with a name, as well as an array of tags. My problem is with the saving the tags...

Angular services issue

javascript,angularjs,angularjs-service
I need some help to understand what is wrong in the following angular service code. EDIT: I have few controllers in different js files that use CRUD API like $http.get('/api/sites/' + service.siteID) or simply need variables directive like templateUrl: '../../' + service.template + ' + '.html' So I create a...

Trying to persist data across controllers using Angular rootScope, but always getting undefined

javascript,angularjs,angularjs-scope,angularjs-service,angularjs-routing
I have an administrator login page. When a user successfully logs in as an admin, I want to display at the top of all pages the user visits: <!-- nav bar --> <div> <span ng-show="$root.isAdmin">(ADMIN)</span> </div> I tried using $rootScope to accomplish this, but I keep getting undefined: // controller...

Using angular factories and services interchangeably - no error

javascript,angularjs,angularjs-service
I am using a service where there should be a factory and I don't get an error. My service returns and object when it should return a constructor function. But my code works perfectly. for example, the code below should not work. But it works fine: angular.module('myApp', []) .service('myService', myService);...

Custom angular service injection failing

angularjs,angularjs-service
I am having an issue injecting my custom service into my controller. When I try to use the controller on the page, I receive the following error: Error: [$injector:unpr] http://errors.angularjs.org/1.3.14/$injector/unpr?p0=<div id="organizations-section" ng-include="'admin/organizations.html'" class="ng-scope">copeProvider%20%3C-%20%24scope%20%3C-%orgService at Error (native) at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js:6:417 at...

$scope variable isn't recognized when calling initialization function

angularjs,angularjs-scope,angularjs-service
I have the following code, where I want to receive all the texts from the current user and show them on screen when the page loads: angular.module('eddieApp') .controller('MainController', function ($scope, Principal, TextService) { $scope.texts = []; Principal.identity().then(function(account) { $scope.account = account; $scope.isAuthenticated = Principal.isAuthenticated; }); $scope.findByUser = function(){ TextService.findByUser($scope.account.login).success(function(data){ $scope.texts...

Unknown Provider Error while trying to test generic angularjs $resource service

angularjs,testing,jasmine,angularjs-service,angular-resource
I have generic service that create resources for my application: (function(module) { module.provider('restService', { resourceRegistry: {}, addRestResource: function(entityName, entityProto) { this.resourceRegistry[entityName] = entityProto; }, $get: function() { var restService; for (var entityName in this.resourceRegistry) { createRestResource(entityName, this.resourceRegistry[entityName]); }; restService = { //createRestResource: createRestResource }; return restService; }}); function createRestResource(entityName, entityProto)...

Update model with $http using a service not triggering model change

angularjs,http,model,angularjs-service
I have the following model: var MODEL = { myTable: [], anotherTable: [] }; //--- initially set as empty arrays MODEL is a global variable as it is used to bind the app model in different controllers. I have devined a service that updates the model, getting the data from...

What's the best way to determine my service is done loading & processing a HTTP get request?

angularjs,angularjs-service
I've got a service in Angular JS which basically performs a HTTP GET & some post-processing like so: angular.module('myApp') .service('graphDataService', function($http) { this.getGraphData() { $http.get('http://localhost:32105/chartData') .then(function(result) { // Perform post processing here }); }; }); What's the best way to communicate with my controller that the GET request and post-processing...