angularjs-service

What does the underscores in _servicename_ mean in AngularJS tests?

谁都会走 提交于 2019-11-27 17:34:21
In the following example test, the original provider name is APIEndpointProvider, but for injection and service instantiation the convention seems to be it has to be injected with underscores wrapping it. Why is that? 'use strict'; describe('Provider: APIEndpointProvider', function () { beforeEach(module('myApp.providers')); var APIEndpointProvider; beforeEach(inject(function(_APIEndpointProvider_) { APIEndpointProvider = _APIEndpointProvider_; })); it('should do something', function () { expect(!!APIEndpointProvider).toBe(true); }); }); What is the convention I'm missing a better explanation

How to access the services from RESTful API in my angularjs page?

試著忘記壹切 提交于 2019-11-27 16:40:26
I am very new to angularJS. I am searching for accessing services from RESTful API, but I didn't get any idea. How can I do that? Option 1: $http service AngularJS provides the $http service that does exactly what you want: Sending AJAX requests to web services and receiving data from them, using JSON (which is perfectly for talking to REST services). To give an example (taken from the AngularJS documentation and slightly adapted): $http({ method: 'GET', url: '/foo' }). success(function (data, status, headers, config) { // ... }). error(function (data, status, headers, config) { // ... });

Stop request in angularjs interceptor

狂风中的少年 提交于 2019-11-27 14:39:57
问题 How can I stop a request in Angularjs interceptor. Is there any way to do that? I tried using promises and sending reject instead of resolve ! .factory('connectionInterceptor', ['$q', '$timeout', function($q, $timeout) { var connectionInterceptor = { request: function(config) { var q = $q.defer(); $timeout(function() { q.reject(); }, 2000) return q.promise; // return config; } } return connectionInterceptor; } ]) .config(function($httpProvider) { $httpProvider.interceptors.push(

AngularJS factory http returns empty

你。 提交于 2019-11-27 11:56:44
I'm trying AngularJS for the first time. I'm getting JSON data from a http-get request using a factory, but the object is returned empty, before the ajax-request is done. Factory: myDemo.factory('photosFactory', function($http) { var photos = []; var factory = {}; factory.getPhotos = function() { $http({ url: 'content/test_data.json', method: 'GET' }).success(function(data, status, headers, config) { photos = data; return photos; }); }; return factory; }); Controller: controllers.AppCtrl = function($scope, $location, $http, photosFactory) { $scope.photos = []; init(); function init() { $scope

Firebase data normalized. How should I fetch a collection based on this structure?

会有一股神秘感。 提交于 2019-11-27 11:51:19
I think I am getting close, I am able to print out the ID of books belonging to a user but have been trying unsuccessfully to fetch the list of books belonging to a user, from the firebase books reference. I'm following loosely the tutorial here: http://www.thinkster.io/pick/eHPCs7s87O/angularjs-tutorial-learn-to-rapidly-build-real-time-web-apps-with-firebase#item-526e9330d90f99661f00046c and also reading the documentation about denormalizing data here: https://www.firebase.com/blog/2013-04-12-denormalizing-is-normal.html How should I go about it if I want to display the user in a page,

AngularJS Error: $injector:unpr Unknown Provider

耗尽温柔 提交于 2019-11-27 10:41:31
问题 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. This is my code for my app including the declaration, configuration and factory definition. EDIT I've now added all of the files to help troubleshoot EDIT The full details of the error are below the issues appears to be with getSettings, as it's looking for getSettingsProvider and cannot

$watch inside a service?

Deadly 提交于 2019-11-27 10:05:20
问题 Is it possible to set up a $watch on an array of objects inside a service (I'd like the $watch declaration itself to be inside the service)? 回答1: You can add any expression to the set of watches by injecting the $rootScope and using a function a first argument to the $watch method. Pseudo-code: $rootScope.$watch(function() { return //value to be watched; }, function watchCallback(newValue, oldValue) { //react on value change here }); Don't forget about the third, Boolean argument to the

AngularJS, is this way of using service good?

好久不见. 提交于 2019-11-27 10:01:13
问题 i've this HTML: <p>Hello {{name}}</p> and the controller is: function myCtrl(scope, service) { scope.name = service.getUsername(); // service.getUsername() return "World!" } myCtrl.$inject = ['$scope', 'originalService']; The service works fine, so i don't paste the code here... In this case the result is " Hello world! " I changed the HTML in this way: <p>Hello {{service.getUsername()}}</p> But this does not work. I changed the controller: function myCtrl(scope, service) { scope.ser =

Linking one controller to another to call service on ng-click

馋奶兔 提交于 2019-11-27 09:54:20
I have two templates with respective controllers and service files. One template's(fleetListTemplate) controller(fleetListController) loads data from its service file(fleetService) and displays in its view(fleetListTemplate). When this happens, and I click on one of the loaded data from fleetService, I should link fleetListController to fleetSummaryController to get data from its service file (fleetSummaryService) and display in fleetSummaryTemplate view. Can someone please help me with the coding? Thank you. The following are the respective modules, templates, controllers and service files.

How can I define an AngularJS service using a TypeScript class that doesn't pollute the global scope?

时光总嘲笑我的痴心妄想 提交于 2019-11-27 09:51:04
问题 I am using AngularJS and TypeScript. I want to implement an AngularJS service using a Typescript class, like this: class HelloService { public getWelcomeMessage():String { return "Hello"; } } angular.module('app.services.helloService', []).factory('helloService', () => { return new HelloService(); }); This compiles to the following javascript code: var HelloService = (function () { function HelloService() { } HelloService.prototype.getWelcomeMessage = function () { return "Hello"; }; return