logo
down
shadow

Consuming my promise inside my Angular component


Consuming my promise inside my Angular component

By : Angus Mol
Date : November 19 2020, 03:01 PM
I think the issue was by ths following , You should add the res.json().results as a parameter when calling resolve, like this: resolve(res.json().results);.
Then when you get the promise, call .then() on it to get the value.
code :
this.innergridService.loadAccountList()
    .then(result => this.promiseRowData = result);
async loadAccountList() {
    return new Promise((resolve, reject) => {
        this.http.get(`${this.baseUrl}`)
            .toPromise()
            .then(
                res => {
                    this.results = res.json().results;
                    resolve(res.json().results);
                },
                msg => {
                    reject(msg);
                }
            );
    });

}
async ngOnInit(): void {
    ...
    // my JSON array from promise
    this.promiseRowData = await this.innergridService.loadAccountList();
}


Share : facebook icon twitter icon
Consuming Custom Angular AOT Component Library - Unexpected token t in JSON

Consuming Custom Angular AOT Component Library - Unexpected token t in JSON


By : jiangyan
Date : March 29 2020, 07:55 AM
wish of those help After some investigation, I found that the metadata.json files generated for components that have a template were invalid. More specifically, ngc inlined the template html inside of the metadata.json as a property, but there were a few issues:
the template property was not wrapped in quotes e.g: "template" the value of the template property was wrapped in single quotes rather than double quotes
How to call a method in parent component from child component in angular 4 within a promise?

How to call a method in parent component from child component in angular 4 within a promise?


By : IGTbob
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , I am trying to call a method in the parent component from the child component in angular 4 using .emit(); , In Child component you should initialize the EventEmitter.
code :
@Output() loadMoreData : EventEmitter<boolean> = new EventEmitter<boolean>(false);
Wait for Promise before calling another promise from inside a for loop - Angular

Wait for Promise before calling another promise from inside a for loop - Angular


By : bkviv
Date : March 29 2020, 07:55 AM
wish of those help Problem: I need to call an API one after the other from inside the for loop. I need to wait for former API to resolve before calling the latter one. , You can use async/await.
code :
**async** ExtendedMethod() {
    let MList: PendingListMemberWise[] = [];
    for (let i = 0; i < this.MemberList.length; i++) {
      if (this.MemberList[i].checked) {
        MList.push(this.MemberList[i]);
      }
    }
    this.ShowLoader = true;
    for (let i = 0; i < MList.length; i++) {
      this.lblText = "Generating PDF " + i + "/" + MList.length;
      **await** this.callGeneratePDFAPI(MList[i]);
    }
    this.lblText = "PDF Generation Completed";
    this.GetBranchList();
    this.ShowLoader = false;
    //this.appconfig.Message="PDF Files have been Generated , Use the Download PDF Link to Download Them";
  }

  callGeneratePDFAPI(mcodeList: PendingListMemberWise) {
    var url = this.baseurl + 'api/GeneratePDF/GeneratePDF/' + mcodeList.memberCode + '/' + sessionStorage.getItem("UserID");
    const service = this.http.get(url).toPromise();
    service.then(result => {
        var index = this.MemberList.indexOf(mcodeList);
        if (index > -1) {
          this.MemberList.splice(index, 1);
        }
      })
      .catch(error => {
        console.error(error);
      });
      return service;
  }
load native web component (non angular component) inside angular web component

load native web component (non angular component) inside angular web component


By : user2326164
Date : March 29 2020, 07:55 AM
I hope this helps you . As long as the native component is properly defined it should load anywhere. Don't forget to call customElements.define('hello-comp', HelloComponent); after defining the class HelloComponent
I assume you are using es6 imports so you will need to import the HelloComponent file in your angular file.
Angular using promise with generics inside promise

Angular using promise with generics inside promise


By : user3329569
Date : March 29 2020, 07:55 AM
wish help you to fix your issue I need to interlace promises in my app: , There are a couple of problems there.
code :
protected scroll<T>(path: string, pageSize: number, filter: string, data: T[]): Promise<T[]> {    
    // *** Return the result of calling `then` on the promise from `toPromise`
    return this.httpClient
        // *** Don't use <T[]> on `get` and `toPromise`
        .get(this.appConfigService.buildApiUrl(path), { params })
        .toPromise()
        .then((result: T) => { // *** <== Note the `T`
            // *** If it's really possible that `result` will be falsy and you don't want that
            // to be valid, you can do this:
            if (!result) {
                throw new Error("appropriate error here");
            }
            return data.concat(result);
        });
}
protected scroll<T>(path: string, pageSize: number, filter: string, data: T[]): Promise<T[]> {    
    if (!filter) {
        const params = new HttpParams()
           .set('searchText', '')
           .set('skip', data.length.toString())
           .set('take', pageSize.toString());

        return this.httpClient
            // *** Don't use <T[]> on `get` and `toPromise`
            .get(this.appConfigService.buildApiUrl(path), { params })
            .toPromise()
            .then((result: T) => { // *** <== Note the `T`
                // *** If it's really possible that `result` will be falsy and you don't want that
                // to be valid, you can do this:
                if (!result) {
                    throw new Error("appropriate error here");
                }
                return data.concat(result);
            });
    }
    return this.filter<T>(data, pageSize, filter, path);
}
Related Posts Related Posts :
  • Angular 4 Force navigate with refresh
  • Query dom element's properties Angular 4
  • Angular Material Dialog return value
  • Accessing HTTP Error Response Body from HttpInterceptor in Angular
  • Resolve Adal Token for Http Interceptor
  • Is it possible to change namespace name in @nrwl/nx?
  • Angular 4 Router: Getting redirected inside children's first route
  • Uncaught Error: Template parse error There is not such directive with exportAs
  • How can I use @HostListener('window:beforeunload') to call a method?
  • Is it possible to get the type from a generic, given as parameter
  • Ionic 3 - Preventing browser close
  • How to set the color of an icon in Angular Material?
  • how do i handle POST response
  • constructor being called duplicate in *ngFor due to @ViewChild
  • Angular4 OAuth2 IdentityServer4
  • ERROR TypeError: Cannot read property 'name' of undefined
  • Angular4 http get with URL parameter
  • What is the difference between fakeAsync's tick() and done() in angular2 testing?
  • How to push in service without losing previous data?
  • How to make custom arrow mark in agm-map?
  • Upload File in Angular 4 using FormData works in Local but not on Azure App Service
  • How to automatically deploy a Laravel app with embedded Angular to Heroku
  • Unexpected module 'Ng2SmartTableModule' declared by the module 'AppModule'
  • use angular-cli project with visual studio asp.net empty web app?
  • How to load different templates for the same component?
  • Creating Angular4 'Loading' Screen: ExpressionChangedAfterItHasBeenCheckedError
  • How to pass a array value as color in Angular 4
  • Coerce the HttpResponse into an item of the specified type, complete with custom methods
  • Angular/rxjs: Why don't I have to import toPromise anymore?
  • Angular 2 @Input not works for router outlet
  • Nested Model - Angular 2
  • Supress duplicate error in aot compiler
  • Angular2 ExpressionChangedAfterItHasBeenCheckedError
  • Despite error cannot read property length of null, the code works
  • Accessing data returned by Promise.all
  • How to add background image with ngStyle?
  • Property X doesn't exist on type Y[]
  • Ionic Headers Failing to set through http.post
  • Angular 4 routing/state problems
  • Angular 2 Dashboard application web api call at initialization
  • ngrx/store:subscribe works fine but async in template gives [object Object]
  • Angular2 - how to mix custom and declared arguments in constructor
  • Implementing Geolocation from @ionic-native/geolocation
  • Angular - Test library before publish
  • AoT Compilation Failed - no such file or directory, lstat 'tsconfig-aot.json'
  • Docker container from Angular4 app : "-p" : executable file not found in $PATH
  • Invalid container name
  • Angular - NgStyle fall back image
  • Angular Observable not updating when I subscribe.
  • Angular mat-checkbox getElementById
  • Angular 4 Injecting route in the APP_INITIALIZER
  • Error: EACCES: Error: EACCES: permission denied, open '/Users/emilio/.ionic/daemon.log' at Error (native)
  • selected value in dropdown list does not work Angular
  • how to smooth scroll down to element on page load angular 4?
  • AngularFire update breaks the app
  • experimentalDecorators Warning on ts lint
  • Dexie - Check if a record exists and initialize it if not present
  • How should I use BehaviorSubject class from a Service in the HTML Template of a Component in Angular 4?
  • How to make ngx-bootstrap datepicker be able to select and display only month and year?
  • What is wrong with this Angular form that makes it reset selected values in the UI unexpectedly?
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org