logo
Tags down

shadow

Angular 8: Observable.subscribe Makes my user class empty


By : M16fa 1070
Date : September 15 2020, 06:00 AM
This might help you It is asynchronous, so you have to put it into the subscribe block. It is not possible to assign it outside of the block, since the subscription doesn't wait and it continues. That's why it is undefined.
code :
GetUserDetailsfromID(id:number) {   
    this.dataSource.GetUserDetailsfromID(id).subscribe(x => {
        this.userresp = x;
        console.log(this.userresp);
        var data = this.userresp; 
    });
}
GetUserDetailsfromID(id:number): Observable<any> {   
    return this.dataSource.GetUserDetailsfromID(id);
}
{{ GetUserDetailsfromID() | async }}



Share : facebook icon twitter icon

How to subscribe to an observable that subscribes to another observable and collide on next's in Angular?


By : veggie
Date : March 29 2020, 07:55 AM
I wish this help you I'm creating a service that requires info about a part of the current path. So, in my component, I have to take a peek at the route and as it's completed I need to subscribe to the actual service call like shown below. , My idea is
code :
this.activatedRoute.paramMap.pipe(switchMap((param: ParamMap) => {
      //Not return params
      let id: number = param.has('id') ? parseInt(param.get('id')) : 0;
      //return this.itemService.getItem(id)
      return this.itemService.getItem(id)
    }))
    .subscribe((item:any)=>{
      this.item=item
    })

Writing an observable that you can subscribe too and makes an http call once


By : Kirtish Srivastava
Date : March 29 2020, 07:55 AM
help you fix your problem At the recommendation of @JB Nizet in the comments above I refactored my call to this:
code :
call(): Observable<...>{
    return service.observable = service.observable || this.httpClient.get<...>(...)
        .pipe(
            map(data => {
                ...
                return ...;
            }),
            shareReplay(1)
        );
}

what is difference between .subscribe() without observable and with observable in latest angular?


By : krishnakishore
Date : March 29 2020, 07:55 AM
seems to work fine Check this link for information about the "subscribe" method: https://rxjs.dev/api/index/class/Observable#subscribe
And this link about the Observable class: https://rxjs.dev/api/index/class/Observable

angular rxjs subscribe to second observable onlly if first observable is null


By : lc.saqib
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I have two methods that return observables. If first returns some data then no need to call the second method. But if the first method returns null then only call the second method. , It's better to use for example concatMap:
code :
import { EMPTY } from 'rxjs';
import { concatMap } from 'rxjs/operators';

this.getdefaultAddress(id)
  .pipe(
    concatMap(data => data === null ? EMPTY : this.getFirstAddress(id)),
  )
  .subscribe();

Declaring an Observable inside a Observable.subscribe() in Angular 2


By : SauliMegaSuper
Date : March 29 2020, 07:55 AM
To fix this issue I approach this by sharing an observable and storing the results within the service. Whenever a component needs that data, it can used the stored result instead of making a new request (https://plnkr.co/edit/M9ZIViYhSbKzPlzKXC7H)
Related Posts Related Posts :
  • how to get route name from current url in angular 7
  • How to show time along with date using Angular Material Date Picker?
  • how to use another component in a lazy loaded component in angular
  • Is there a way to create mechanical relations between models in P5.js?
  • Angular: Reference current component in event listener on window
  • How to create child router-outlet in a lazy loaded feature module?
  • How can i open ng bootstrap dropdown menu by default
  • Azure Devops Angular Environment Variables
  • Directive @Input variable not getting update when component update the value
  • How to do the filtering in a pipe of a resolver in Angular?
  • How do i show and hide details on a single item on click
  • How to integrate StropheJs with Angular 8
  • force function parameter keyword in TypeScript(Angular)
  • How should i import the sass files in angular
  • Cards in Angular/Bootstrap
  • Why should I use Redux in Angular as far as Angular is two-way data binding?
  • Sending output from child component to parent Angular
  • Hot to apply a pipe on a reactive form field
  • How do I copy an entire directory into dist/ using custom webpack with angular-builders?
  • Primeng table p-table,set conditional column editable
  • Get the value out of subscribe() Angular 7
  • How to convert this string into template literal
  • Retry getting result from backend server if certain condition not met
  • Does takeUntil on forkJoin calls the function on forkJoined observables?
  • Angular build for production error with PrimeNG
  • How to close Angular Material Sidenav with escape?
  • Angular: Why is ViewChild with QueryList returning only the first instance?
  • Breeze.js and State Management
  • Angular default app ng serve: privacy error in Chrome: NET::ERR_CERT_AUTHORITY_INVALID
  • unit test does not coverage code of the method with swithcmap and tap
  • Can we put disable property to the icons based on condition in angular
  • Error: Please, upgrade your dependencies to the actual version of core-js@3
  • Angular Browserslist: caniuse-lite is outdated. Please run next command `npm update`
  • How to wait for all inner HTTP calls to complete?
  • ng serve --prod fails after upgrading to angular 8
  • What is the difference between the unsubscribe() method in Subject and Subscription class?
  • is jquery installed by default when you install angular app(8) by angular cli?
  • How to loop through section elements to project with ng-content
  • Angular - Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding
  • Auth0 is failing localauthsetup 3 times and later i am able to route to the home page
  • Add active class to an element in a ngFor loop before click event is fired
  • Angular Json data display in component html
  • Jhipster - Angular receive navigation of other users
  • How to do angular reactive form validation for a number of 10 digits
  • Infinite loop happening with effects - Angular ngrx8
  • How to execute a function before modal closes?
  • How to remove previous polyline automatically before adding new path
  • Facing issue 'A MatDatepicker can only be associated with a single input.' Angular 8 Material
  • npm WARN deprecated core-js@2.6.11: core-js@<3 is no longer maintained and not recommended for usage due to the numbe
  • How to fetch data from java REST API using Angular 7?
  • value getDay is not a function Typescript Angular
  • Trying to use same component with different templates
  • How do I implement a app-wide notification feature when there is a change in my Firestore collection in Ionic 3?
  • ERROR TypeError: Cannot read property 'split' of null in angular custom pipe
  • Angular async pipe with rxjs switchmap
  • How to display a mat-error message without a form control, but with matInput?
  • How to keep router link active state on if the parent route is activate
  • Behavior subject has different emit count on value change
  • Is there a way to get mat-icon by id and change the value of matBadge={{0}}
  • Angular Elements - ViewEncapsulation
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk