angular-services

Should I use readonly on injected Angular services instead of making them public?

旧城冷巷雨未停 提交于 2021-02-09 11:45:49
问题 I had a discussion today where some of my colleagues said that they inject their Angular services like that: constructor(readonly language: I18nService) They said they do this because it prevents consumers of my component to change the injected service, kinda like that: @Component({ ... }) class ComponentA { constructor(public language: I18nService) {} } @Component({ ... }) class ComponentB { @ViewChild(ComponentA) compA: ComponentA; constructor() { this.compA.language = new I18nService(); }

Yet another “Can't bind to 'ngIf'”

懵懂的女人 提交于 2021-02-08 05:17:10
问题 I've looked at dozens of posts here and elsewhere with the same error message, plus the entire modules FAQ, but still haven't found a solution that works in my case. (E.g., questions 35543028, 35939950, 40426432, 40828068, 44898901, 45436552, 47660922, 50200329, 59212318...) They pointed out these things to check: Correct capitalization of ngIf: check The main module imports BrowserModule: check The module that creates the component imports CommonModule: N/A; the component comes from the main

Yet another “Can't bind to 'ngIf'”

≯℡__Kan透↙ 提交于 2021-02-08 05:15:30
问题 I've looked at dozens of posts here and elsewhere with the same error message, plus the entire modules FAQ, but still haven't found a solution that works in my case. (E.g., questions 35543028, 35939950, 40426432, 40828068, 44898901, 45436552, 47660922, 50200329, 59212318...) They pointed out these things to check: Correct capitalization of ngIf: check The main module imports BrowserModule: check The module that creates the component imports CommonModule: N/A; the component comes from the main

Generic type Subject<T> requires 1 type argument(s). - Angular

泄露秘密 提交于 2021-02-07 11:46:15
问题 I'm getting data from my service and I've red about it's important to unsubscribe after subscribe, and here is how I did it: export class RItemComponent implements OnInit { apiPath = environment.apiUrl; private ngUnsubscribe: Subject = new Subject(); constructor(private _sharedService: SharedService) { } rItems: Product[]; ngOnInit() { this._sharedService. getReceiptItem().takeUntil(this.ngUnsubscribe). subscribe(products => this.rItems = products); } ngOnDestroy() { this.ngUnsubscribe.next()

Angular 9 Service as Obesrvable in library

不想你离开。 提交于 2021-01-29 19:56:24
问题 I am working on multiapplication setup, where inside workspace 2 or 3 applications will share library with common and shared components. Currently, I am adding notifications service. Added (at least for now) as part of library main module. As base I am using this example from stackblitz or this one When calling notification service from inside library (which is inside the same module as notification.component: this._notificationSvc.success('Hello World','This is a success !'); the service

Angular/RxJS update piped subject manually (even if no data changed), “unit conversion in rxjs pipe”

ε祈祈猫儿з 提交于 2021-01-29 14:30:55
问题 I am working on an app using Angular 9 and RxJS 6.5. The functionality I have problems with uses Angular services to fetch some data from a server and provides this data to views (using RxJS behaviorSubjects). Before passing that data to the views though, I want to do some unit conversion, so that the user can use a toggle/switch to change between two units for the entire app, specifically "metric tons" and "short tons". While the actual conversion functions are provided within a dedicated

How to limit API calls per second with angular2

夙愿已清 提交于 2021-01-21 09:03:43
问题 I have an API limit of 10 calls per second (however thousands per day), however, when I run this function (Called each Style ID of object, > 10 per second): getStyleByID(styleID: number): void { this._EdmundsAPIService.getStyleByID(styleID).subscribe( style => {this.style.push(style); }, error => this.errorMessage = <any>error); } from this function (only 1 call, used onInit): getStylesWithoutYear(): void { this._EdmundsAPIService.getStylesWithoutYear(this.makeNiceName, this.modelNiceName,

How to limit API calls per second with angular2

淺唱寂寞╮ 提交于 2021-01-21 09:02:22
问题 I have an API limit of 10 calls per second (however thousands per day), however, when I run this function (Called each Style ID of object, > 10 per second): getStyleByID(styleID: number): void { this._EdmundsAPIService.getStyleByID(styleID).subscribe( style => {this.style.push(style); }, error => this.errorMessage = <any>error); } from this function (only 1 call, used onInit): getStylesWithoutYear(): void { this._EdmundsAPIService.getStylesWithoutYear(this.makeNiceName, this.modelNiceName,

Angular cross-service communication

谁说胖子不能爱 提交于 2020-12-06 07:06:26
问题 I have a statistics application. On the left side of my page I have list of themes, on the top - list of groups. The main part contains statistics items related to both theme and group. Also I have several services which provide business logic for my application. For simplicity let's talk about three of them: ThemeSerivce, GroupService and StatisticsService . End users could manipulate lists of themes and groups (add or remove items) and I have to recalculate statistics after each change. In

Way to inject angular FormBuilder service to dynamic component

别来无恙 提交于 2020-11-28 09:16:59
问题 I'm trying to inject the FormBuilder service to a dynamic component this way: Template: ... <div #vc></div> ... Component: @ViewChild('vc', { read: ViewContainerRef }) _container: ViewContainerRef; ... constructor(private fb: FormBuilder, private componentFactoryResolver: ComponentFactoryResolver, private _compiler: Compiler, private _injector: Injector, private _m: NgModuleRef<any>) { } ... ngAfterViewInit() { let allPms: any[] = null; let template = ''; // construct template on the fly