Posts

Showing posts with the label Observable

Angular5: Need To Prevent NgbTooltip From Rendering Before Data Is Returned From Observable

Answer : Look into using OnInit lifecycle hook which is processed first when a component is loaded. Documentation For ngOnInit Thats simple enough, then move that call to the service as seen below into the life cycle hook. Give the class a public variable ie public toolTipData: string; (moved into OnInit) this.planService.getAuditDetails(planId, fieldName, fieldValue) .subscribe((auditDetail: AuditDetail) => { this.tooTipData = auditDetail.toolTipInfo // (guessing at name) this.auditDetail = auditDetail; this.loadCompleted = true); }, (errors) => { console.log(errors) // api error status code. } }); In the HTML set the tool tip value to [ngbTooltip]="toolTipData" This should help populate the tool tip appropriately. The asynchronous changes aren't showing up because NgbTooltip window uses ChangeDetectionStrategy.OnPush and the only way to trigger change detection is calling open() on a closed tooltip. In order t...

Async/await In Angular `ngOnInit`

Answer : It is no different than what you had before. ngOnInit will return a Promise and the caller will ignore that promise. This means that the caller will not wait for everything in your method to finish before it proceeds. In this specific case it means the view will finish being configured and the view may be launched before this.data is set. That is the same situation you had before. The caller would not wait for your subscriptions to finish and would possibly launch the app before this.data had been populated. If your view is relying on data then you likely have some kind of ngIf setup to prevent you from accessing it. I personally don't see it as awkward or a bad practice as long as you're aware of the implications. However, the ngIf can be tedious (they would be needed in either way). I have personally moved to using route resolvers where it makes sense so I can avoid this situation. The data is loaded before the route finishes navigating and I can...

Angular 4+ NgOnDestroy() In Service - Destroy Observable

Answer : OnDestroy lifecycle hook is available in providers. According to the docs: Lifecycle hook that is called when a directive, pipe or service is destroyed. Here's an example: @Injectable() class Service implements OnDestroy { ngOnDestroy() { console.log('Service destroy') } } @Component({ selector: 'foo', template: `foo`, providers: [Service] }) export class Foo implements OnDestroy { constructor(service: Service) {} ngOnDestroy() { console.log('foo destroy') } } @Component({ selector: 'my-app', template: `<foo *ngIf="isFoo"></foo>`, }) export class App { isFoo = true; constructor() { setTimeout(() => { this.isFoo = false; }, 1000) } } Notice that in the code above Service is an instance that belongs to Foo component, so it can be destroyed when Foo is destroyed. For providers that belong to root injector this will happen on application destroy, t...

BannerAd.dispose Not Working Flutter Admob

Answer : You need to dispose the banner like this try { _myBanner?.dispose(); _myBanner = null; } catch (ex) { log("banner dispose error"); }