angularjs-service

Angular JS: why the difference between module.config injection and controller injection?

北城余情 提交于 2019-12-03 15:24:34
This is something that I could not figure out from digging into the AngularJS code, maybe you can help solve the mystery. To show it, I added a service to AngularJS seed project: function MyServiceProvider() { console.log('its my service'); this.providerMethod = providerMethod; function providerMethod() { console.log('its my service.providerMethod'); } this.$get = $get; function $get() { var innerInjectable = { name: 'stam' }; return innerInjectable; } } var serviceModule = angular.module('myApp.services', []). value('version', '0.1'). provider('myservice',MyServiceProvider); You can see that

Angular modal dialog best practices

荒凉一梦 提交于 2019-12-03 14:53:54
What is the best practice for creating modal dialogs with dynamic content, contrasted with dialogs that don't have dynamic content. Eg.. We have some modal forms that accept a list of form elements, and have submit/cancel. Also, there are modal dialogs that just display a confirm/ok type of operation. I've seen a lot of people saying that dialogs should be services passed into the controller, but it seems to me that services shouldn't be rendering UI components and manipulating the DOM. What is the best practice for assembling these two types of dialogs? Thanks. Angular UI Boostrap provides a

Share async data between controllers without making multiple requests

≡放荡痞女 提交于 2019-12-03 12:26:52
I'm trying to make a single $http request to get one of my JSON files and use the data across all my controllers. I saw on egghead.io how to share data across multiple controllers, and I've also read this StackOverflow question: " Sharing a variable between controllers in angular.js ". However, the answers there don't use the $http module. When using $http , the controllers don't have the data to work on, and by the time the response is received it's already too late. I then found the method $q.defer and this question on StackOverflow: " AngularJS share asynchronous service data between

AngularJS and Typescript - Injecting Services

纵饮孤独 提交于 2019-12-03 12:23:22
问题 I have been writing AngularJS apps for awhile now, but Typescript is new to me, and then adding in AngularJS to Typescript is a bit different than I am use to. Anyways, what is the difference between the two: app.service('customerDataService', Application.Services.CustomerDataService); and app.service('customerDataService', ['$http', '$q', Application.Services.CustomerDataService]); Controller TS module Application { export module Services { export interface ICustomerDataService { getCustomer

The better approach to design AngularJS services

陌路散爱 提交于 2019-12-03 10:48:05
问题 I'm writing an AngularJS client application that would interact with a REST server. To manage the client / server interaction I'm using the $resource abstraction. Actually I'm writing every resource as a separated service and injecting it only in the controllers that are gonna use it. I've started to develop using the angularjs-seed, so in my separed services.js file I've got an increasing number of services: angular.module('testReqService', ['ngResource']). factory('TestReq', function(

Use service into View AngularJS

纵饮孤独 提交于 2019-12-03 09:48:39
I have issue with angularJS Service. I have simple service: angular.module('mainApp.services', []).factory('AuthService', function ($http) { //var currentUser = null; //var authorized = false; //AutoLogin for testing var currentUser={email: "example@example.com", id: "15"}; var authorized=true; // initial state says we haven't logged in or out yet... // this tells us we are in public browsing var initialState = false; return { initialState:function () { return initialState; }, login:function (userData) { //Call API Login currentUser = userData; authorized = true; initialState = false; },

AngularJS - extending module with own types / providers

孤街浪徒 提交于 2019-12-03 09:45:10
问题 I want to ad a new (dialog) type to angular, so I could use it just like I use module.directive , module.filter , module.controller to register directives, filters and controllers. I want to register my instances of dialog type this way: module.dialog('prompt',function(dependencies){ return { templateUrl:'prompt.html', controller:function($scope){}, something:'value' } }); I also want to be able to use registered dialogs in controllers (dependency injection) module.controller('ListCtrl'

AngularJS ui-router: how to resolve typical data globally for all routes?

爱⌒轻易说出口 提交于 2019-12-03 09:02:48
问题 I have an AngularJS service which communicates with the server and returns translations of different sections of the application: angular .module('utils') .service('Translations', ['$q','$http',function($q, $http) { translationsService = { get: function(section) { if (!promise) { var q = $q.defer(); promise = $http .get( '/api/translations', { section: section }) .success(function(data,status,headers,config) { q.resolve(result.data); }) .error(function(data,status,headers,config){ q.reject

Combining resources in AngularJS

为君一笑 提交于 2019-12-03 09:02:17
I have a RESTful API that provides me with employees and departments. In my AngularJS app, I need to know the employee and the departments the employee belongs to. I have defined two factory services for that: angular.module('myApp.services', []) .factory('Employee', function ($resource) { return $resource ('/api/employees/:id', { id: '@id' }); }) .factory('Department', function ($resource) { return $resource ('/api/departments/:id', { id: '@id' }); }) ; In the controller, I call: $scope.employee = Employee.get({id: 'me'}); Next, I want to call: $scope.departments = []; angular.forEach($scope

Passing argument(s) to a service in AngularJs

混江龙づ霸主 提交于 2019-12-03 07:20:15
问题 I am trying to configure my first tidbits of the AngularJs for a trivial stuff, but unfortunately unsuccessful at it after considerable amount of time. My Premise: Users select one of the options from a dropdown and have an appropriate template loaded into a div below the select. I have set up the service, a custom directive (by following the ans by @Josh David Miller on this post, and a controller in place. The ajax call in service is working fine except that the params that I pass to the