angularjs-service

Angular controller can't get data from service

非 Y 不嫁゛ 提交于 2019-12-08 12:50:45
问题 Background: I'm learning AngularJS, I've written sample code to create a service for a module, and pass the data from service into one of the module's controller, all works fine. But yesterday when I tried to pass the following service's data into a controller, it just show the data is undefined, and I don't know why. var notif = angular.module('testnotif',[]); notif.service('sharedUsers', ['$http', function($http){ var url = current_dir+'/testNotif/getAllUsersjson'; var allUsers = []; var

AngularJS share asynchronous service data between controllers

非 Y 不嫁゛ 提交于 2019-12-08 10:56:25
I know this issue has been asked several times in stackoverflow, but I couldn't find a proper answer. What I need to achieve is to be able to initiate some asynchronous call in one controller and when the result returns update the $scope in some other controller. I understand that I should use a shared service that actually does the $http stuff, but I can't manage to update the other controller scope. Here is my code: View <div class="screens" ng-controller="framesController"> <div class="scroller scroll-pane" frames-scroll-pane> <div class="overview"> {{frames}} </div> </div> </div> Service

How to define tests with Jasmine for $resource (AngularJS)

此生再无相见时 提交于 2019-12-08 07:50:35
问题 I want to define tests for my angular app but I don't know how to work with because it's my first time to write tests. However, it's important for me to define Tests with Jasmine for REST Service in my application. Well, my question is how can I test the GET requests. I was on the jasmine site and have read the sample there. But it was only a test whether the URL is correctly written. My intention is to check if I get response data back? Is that possible? Also in Angular Doc is written that

'unknown provider error' in Angular app

[亡魂溺海] 提交于 2019-12-08 05:15:54
问题 I followed the Angular docs to create my Service and saw an error message http://docs.angularjs.org/error/$injector:unpr?p0=$scopeProvider%20%3C-%20$scope%20%3C-%20$users This is my code: var angularApp = angular.module("myApp", []); angularApp.run(function($http) { $http.defaults.headers.common['Content-Type'] = 'application/x-www-form-urlencoded'; $http.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; }); angularApp.service('$users', function($scope, $http, $cookie, $window)

angularjs firebase user auth service not communicating with the views

我的梦境 提交于 2019-12-08 04:32:25
问题 I have a service which passes on the parameter pseudonym to the evironment. I call on this pseudonym in my views, but it doesn't appear at all. How can I fix this to display the value in my views? MyUser service : app.service('MyUser', ['DatabaseRef', 'firebase', function(DatabaseRef, firebase) { var pseudonym =""; var userId = firebase.auth().currentUser.uid; return { pseudonym: function() { DatabaseRef.ref('/users/' + userId).once('value') .then(function (snapshot) { pseudonym = snapshot

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

拟墨画扇 提交于 2019-12-08 04:20:13
问题 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 problem is there. When I replace the getUser code by console.log it doesn't give 'undefined' error. <html ng-app="gitHubViewer"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <script src="../angular.min.js

AngularJS. Best practice concerning proper two way data binding from a service

心不动则不痛 提交于 2019-12-08 01:22:44
问题 I have an 'Account' service which acts as a centralized data storage used in multiple controllers and views. This service will hold, besides getter and setter methods all data associated with two types of users, being a logged in user and an anomonous user. The idea behind this service is that it should be used as a centralized data structure which will keep all associated views and controllers in synch. Eg: If a user logs in whe will know his email and all 'newsletter subscription' fields

Angularjs - equal sign in $http post data

谁都会走 提交于 2019-12-07 17:31:53
问题 I'm using angularjs' $http service to post data to my API. It works great.. until I add and equals sign to the contents of data (JSONRequest in example) var request = { 'method': 'POST', 'url': API_URL + apiActionName, 'data': JSONRequest, 'withCredentials': true, }; $http(request). success(function(data, status, headers, config) { // handle success }). error(function(data, status, headers, config) { // handle error } this works for data contain the following JSONRequest { 'text':'this is

Best practice in keeping `$watch` functions away from your controllers

主宰稳场 提交于 2019-12-07 11:25:56
问题 I tried to find some good examples on best practice in moving $watch functions from a controller to a factory, for example. What I have found is that actually there isn't a unanimous opinion on what's best to do. I've seen examples of injection the $rootScope into a factory and $watch ing for value changes there. Another suggestion is to avoid them whenever possible, and to use ngChange instead on the element itself, for example: <div ng-model="foo.bar" ng-change="updateValue(foo.bar)"></div>

ui-route resolve not working

好久不见. 提交于 2019-12-07 08:02:45
问题 My Application needs a some basic data to start. That's why i created a service and I am using it as model for that common data so that it can be accessible to all the controllers. I am trying to resolve the service using ui-route's reslove functionality that says if I return a promise then it will be resolved before the controller's execution begin but it is not working for me. here is my code service: var Data = function ($q, $http) { var list = {}; var cachedData; var resolveData;