sharedservices

Angular insert service in the file.html

孤人 提交于 2020-12-15 05:15:33
问题 I'm using Angular 7 (and one day I have to upgrade my version). I have a service that have some variables that can change according to some Promise (http GET , PUT , ... response). I wish to print these variables on a template. Can I do this: app.component.html: <ng-container *ngIf="this.dogService.isWarningProblem"> <ngb-alert [dismissible]="false" type="warning" style="text-align: center"> {{this.dogService.errorMessage}} </ngb-alert> </ng-container> app.service.ts: export class

Angular 4 emitting and subscribing to an event in a shared service

廉价感情. 提交于 2019-12-07 05:23:43
问题 I am emitting an event in my main component: main.component.ts this.sharedService.cartData.emit(this.data); Here is my sharedService.ts import { Component, Injectable, EventEmitter } from '@angular/core'; export class SharedService { cartData = new EventEmitter<any>(); } In my other (Sub) Component, I want to access this value, but somehow, the subscription does not work: dashboard.ts private myData: any; constructor(private sharedService: SharedService) { this.sharedService.cartData

Angular 4 emitting and subscribing to an event in a shared service

坚强是说给别人听的谎言 提交于 2019-12-05 08:53:44
I am emitting an event in my main component: main.component.ts this.sharedService.cartData.emit(this.data); Here is my sharedService.ts import { Component, Injectable, EventEmitter } from '@angular/core'; export class SharedService { cartData = new EventEmitter<any>(); } In my other (Sub) Component, I want to access this value, but somehow, the subscription does not work: dashboard.ts private myData: any; constructor(private sharedService: SharedService) { this.sharedService.cartData.subscribe( (data: any) => myData = data, error => this.errorGettingData = <any>error, () => this.aggregateData

Example of using Shared Services. Prism

末鹿安然 提交于 2019-11-28 06:34:38
问题 I have 5 modules and I am using EventAggregator pattern to communicate between modules. And it seems to me that my code becomes ugly and it is bad design to use EventAggregator in my project. There are three ways to communicate between modules: Loosely coupled events Shared services Shared resources I would like to know more about communication by Shared Services . What I've found is an article about StockTrader application from Prism ToolKit. Is there some more lightweight and clearer

Angular - shared service between components doesn&#39;t work

房东的猫 提交于 2019-11-26 04:01:47
问题 I have a service where I declare my variable. In my component I use this variable to put data into it. Service: @Injectable() export class DataService { public msgs = []; constructor() { } } Now I use this variable in my component: export class MessagesComponent implements OnInit { constructor(private dataService: DataService){} ngOnInit() { this.getData(); } getData(){ let msgs = []; if (diffr <= this.geomessage[i].range) { this.geomessage[i].dist = diffr; msgs.push(this.geomessage[i]); /