Uncaught ReferenceError: __ng_jsonp____req0_finished is not defined at

前端 未结 2 1518
终归单人心
终归单人心 2021-01-25 03:54

I have an Angular application and I\'m using JSONP as well.

This is my service:

import { Injectable } from \'@angular/core\';
import { Http, Response, He         


        
相关标签:
2条回答
  • 2021-01-25 04:17

    I solved this bug going back to the version 2.3.1 of Angular. The bug happens in the version 2.4.X.

    "@angular/common": "~2.3.1",
    "@angular/compiler": "~2.3.1",
    "@angular/core": "~2.3.1",
    "@angular/forms": "~2.3.1",
    "@angular/http": "~2.3.1",
    "@angular/platform-browser": "~2.3.1",
    "@angular/platform-browser-dynamic": "~2.3.1",
    "@angular/router": "~3.3.1",
    
    0 讨论(0)
  • 2021-01-25 04:20

    Here is my solution:

    set a variable:times
    export class WikipediaService {
      constructor(private jsonp: Jsonp) {
        this.times=0;}
      search (term: string) {
        let wikiUrl = 'http://en.wikipedia.org/w/api.php';
        let params = new URLSearchParams();
        params.set('search', term); // the user's search value
        params.set('action', 'opensearch');
        params.set('format', 'json');
        params.set('callback', `__ng_jsonp__.__req${this.times}.finished`);
        this.times=this.times+1;
        // TODO: Add error handling
        return this.jsonp
               .get(wikiUrl, { search: params })
               .map(response => <string[]> response.json()[1]);
      }
    }
    
    0 讨论(0)
提交回复
热议问题