angular-services

How to get a screen resize dimension from a service in angular 2+?

帅比萌擦擦* 提交于 2019-12-23 21:32:23
问题 First this not duplicated take time to read, because there is lot of similar question but they are in the @Component decorator I got the idea to catch screen resizing in a service then sharing some css value by an observable, but it seem that my service is not working (not able to catch screen resize event). Here is my code import { Injectable, HostListener } from '@angular/core'; import { BehaviorSubject } from 'rxjs'; @Injectable({ providedIn: 'root', }) export class BreakPointService {

Angular: Binding to a observable property of service -> value doesn't update

断了今生、忘了曾经 提交于 2019-12-23 16:06:57
问题 I'm trying to communicate between two browser tabs/windows using BroadcastChannel API. The communication seems to work between two instances of angular service, but changes to the values of the observable are not shown. I'm trying to achieve this using mainly the async pipe. I have a demo of my problem at StackBlitz I have two component that are showed using the router. ( control and display ) I have a service ( MessagingService ) where I have a BehaviorSubject and BroadcastChannel API

How to create Dynamic factory in Angular js?

狂风中的少年 提交于 2019-12-23 09:33:47
问题 In my project i have to create dynamic factory in angular js with dynamic factory name like below function createDynamicFactory(modId) { return myModule.factory(modId + '-existingService', function (existingService) { return existingService(modId); }); } I want to get new factory with dynamic name , when i called this function. unfortunately this is not working. how can i achieve this? and how to inject in my controller or in directive dynamically? 回答1: You can annotate your service generator

How to get data from an API in a Angular Service and store it to be used by anyone in the future

荒凉一梦 提交于 2019-12-23 04:34:13
问题 This is more of a writing clean code/ optimizing existing code. I am writing my Angular Services to fetch data from backend like this angular.module('myApp').service('Auth', ['$http', '$q', 'Config', function($http, $q, Config) { this.getUser = function() { return $http.get(Config.apiurl + '/auth/user') .then(function(response) { return response.data; }, function(error) { return $q.reject(error.data); }); }; }]); Now in this, I am calling getUser function n number of times from the Database.

Angular - inject in other way than constructor?

别等时光非礼了梦想. 提交于 2019-12-22 18:17:38
问题 In Angular, I have a service that has few things injected through the constructor(...) . However that service is also at some place created by calling the constructor. Therefore, adding another service it depends on to the parameters would change the API. I'd like to avoid that. Is there a way to inject a service into another service without adding it to the constructor parameters? E.g. field injection? import {Inject, Injectable} from "@angular/core"; import { Http, Request,

Unknown Provider when adding service to controller

泄露秘密 提交于 2019-12-22 18:04:16
问题 I created a Modal service and when I injected the service into the controller, I am receiving an error that says "$Injector: unpr Unknown Provider". Here is my code below. Let me know if I am missing something. This is the service I have so far. 'use strict'; angular.module('myApp.services', []) .factory('modalService', ['$scope', function($scope) { return { openMenuModal: function(templateLink, windowAnimation) { var modalInstance = $modal.open({ templateUrl: templateLink, backdrop: 'static'

Post Data from two forms as one Object in Angular

旧街凉风 提交于 2019-12-20 03:05:51
问题 This is my first project on Angular and I have done as much as I could and I will try to finish it myself but I feel like that I require help. A brief description of the project : I have a class mod.ts export interface Mod { id : number , name? : string, clauseList? : Clause country? : string; company? : string; process? : string; } export interface Clause { cName? : string, cid? : number, // pc : number, parentC? :number, id? : number, text? : Text } export interface Text { txt? : string,

Angular updating and clearing factory variables

社会主义新天地 提交于 2019-12-20 02:52:35
问题 I'm creating a single page app in which a user searches for a term, the result gets saved in a variable, and a new page is routed that displays the result. I have this functionality working, however I want the variable to be cleared when the user returns to the previous page and most importantly when the user logs out. What's the proper way to do this? I want the factory to save things for certain pages that I want, and clear them for certain pages I don't want like "home" or "logout".

Sharing Data between pages in AngularJS returning empty

三世轮回 提交于 2019-12-19 21:05:37
问题 Typically i write SPA's and sharing data between controllers is simple with a service. I am not using an SPA format (not using ng-view), and trying to share data between pages but on load of the second page (to get data) its empty. PAGE1 (index.html): <div ng-controller="CreateList"> <input type="text" ng-model="myValue"> <div ng-click="share(myValue)">Share</div> </div> PAGE2: <div ng-controller="GeList"> <p>{{ sharedData }}</p> </div> JS: app.controller('CreateList', function($scope,

Extending a base class in an Angular service

删除回忆录丶 提交于 2019-12-18 13:27:12
问题 I have a base class that I would like to extend in a service to help get data in to the angular scope. I have searched around the net for a solution, but have not found one that I like. I have a base class that is used to access the File systems of devices the class structure: var cOfflineStorageBase = Class.extend({ init: function(){ }, CreateFolderDir: function(){ }, DeleteAll: function(){ }, DeleteDirectories: function(){ }, DeleteItem: function(){ }, GetFiles: function(){ }, FileExists: