Issue: There is an Uncaught Promise Error indicating that there is no provider for Jsonp in the code implementation (HTML / Javascript / Typescript / Angular2)

Error displayed in screenshot:

https://i.sstatic.net/bQoHZ.png

.ts file code snippet (SearchDisplay.component.ts):

import {Component, OnInit} from 'angular2/core';
import {Router} from 'angular2/router';
import {Hero} from './hero';
import {HeroService} from './hero.service';
import {RouteConfig, ROUTER_DIRECTIVES} from 'angular2/router';
import {HeroesComponent} from './heroes.component';
import {HeroDetailComponent} from './hero-detail.component';
import {DashboardComponent} from './dashboard.component';
import {SpreadSheetComponent} from './spreadsheeteditall.component';
import {SwitchUsersComponent} from './SwitchUsers.component';
import {BiddingPageComponent} from './BiddingPage.component';
import { Injectable } from 'angular2/core';
import { Jsonp, URLSearchParams } from 'angular2/http';



@Component({
  selector: 'SearchAndDisplayComponent',
  templateUrl: 'app/SearchDisplay.component.html',
  styleUrls: ['app/SearchDisplay.component.css'],
  providers: [HeroService],
  directives: [ROUTER_DIRECTIVES]
})

@Injectable()

export class SearchAndDisplayComponent{
   constructor(private jsonp: Jsonp) {}
  search (term: string) {
    let ebayURL = 'http://developer.ebay.com/Devzone/XML/docs/reference/ebay/index.html';
    var params = new URLSearchParams();
params.set('search', term); // user's search value
    params.set('action', 'opensearch');
    params.set('format', 'json');
    params.set('callback', 'JSONP_CALLBACK');
    
    return this.jsonp
               .get( ebayURL, { search: params })
               .map(request => <string[]> request.json()[1]);
  }


}

Code excerpt from .html file that could be the source of the error (SearchDisplay.component.html):

<input class="search2" id="txtSearch" type="text" name="serach_bar" size="31" maxlength="255"       
value="" style="left: 396px; top: 153px; width: 293px; height: 26px;" />
<input class="search1" type="submit" name="submition" value="Search" style=" padding-  
bottom:20px; left: 691px; top: 153px; height: 23px" />
<button (click)="search(term)">Search</button>
<script type="text/javascript">
    document.getElementById('frmSearch').onsubmit = function() {
        window.location = 'local data here (not sure how to code this)' + document.getElementById('txtSearch').value;
        return false;
    }
</script>

Context of issue: Trying to implement a search bar functionality similar to eBay on a website.

The original code was adapted from a Wikipedia example but needs modification to fetch data from eBay or create a local search restricted to "apple" and "car".

Link to Plunker/zipped project files provided in this post:

Search bar that hides results not typed into it

Answer №1

For those currently looking for a solution in Angular 2 now that it's finalized, you can resolve this issue by including the JsonpModule in your app.module.ts file like this:

import { HttpModule, JsonpModule } from '@angular/http';

@NgModule({
    declarations: [],
    imports: [
        HttpModule,
        JsonpModule
    ],
    providers: [],
    bootstrap: []
})

Answer №2

Ensure that you have included JSONP_PROVIDERS in the provider you are injecting at a higher level, such as when bootstrapping your application or within a parent component.

To learn more about JSONP_PROVIDERS, click here.

Remember to include JSONP_PROVIDERS either in a component's injector or in the root injector when launching an application.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Saving data in JSON format at a particular location

My JSON data contains various items that need to be placed in specific positions within a form. Is it possible to achieve this? var objs = [{ "Object1": { "ID": 1, "type": "input", "color": "red", "Text": "DARKDRAGON", "wid ...

Contrasting the impact of opening your HTML files from the desktop versus running a development local server for your files

As I delve into web design, I've noticed a trend on YouTube where creators utilize virtual servers to upload and preview their code. This got me thinking - what advantage does using a local server offer compared to simply opening the HTML file in my b ...

Issue encountered while attempting to adjust a date (the modification was incorrect)

I am currently working on developing a calendar feature using Angular. Part of this project involves implementing drag and drop functionality to allow users to move appointments from one day to another. However, I have encountered a strange issue. When at ...

Add a library to a server with npm installation

When needing to incorporate a library like Croppie, the installation process involves using npm or Bower: npm install croppie bower install croppie Given that I am working on a server, I'm uncertain where to install it. Should it be on the server it ...

Resolving problem in React component: TypeScript error - Unable to find property 'type' on 'string' type

In my React typescript component, I have defined a custom block that filters and displays data: type CustomTeaser = Exclude<Teaser, TeaserThree>; const MyCustomBlock = ({ customItems }: Props) => { const sixGridData = { items: customItems as Cu ...

The success callback in the first call will only be triggered when a breakpoint is established

I currently have an ASP.NET MVC webpage with Bootstrap and several plugins integrated. I am attempting to implement a confirmation message using the Bootbox plugin before deleting a record, followed by reloading the page upon successful deletion. Everythi ...

Exploring proactive search using RxJS Observable compared to Subject

Two different methods have been presented for tackling the same issue, which is to conduct a real-time search for specific characters entered by the user in a text box. The first solution is derived from the ngrx example, while the second solution is from ...

Retrieving information from a text document by means of data-src with the assistance of jQuery

Trying to extract text from a .txt file using jQuery while utilizing Bootstrap. New to web design with some coding experience. Button in HTML: <button type="button" class="btn btn-primary-outline-btn text-btn" data-toggle="modal ...

Angular 14.2.9: "Trouble with Form Data Binding - Seeking Assistance with Proper Data Population"

I'm currently using Angular version 14.2.9 and the component library I'm utilizing is: import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; While working on binding data to a form, I encountered an issue where the data wasn't d ...

Converting HTML table text to JSON data using vanilla JavaScript (without any external libraries like Selenium)

As a newcomer to programming and Javascript, my goal is to use Selenium Webdriver in Visual Code to extract HTML table content from a webpage and convert it into JSON data. I've managed to retrieve the table data, but I'm struggling with the conv ...

How to eliminate the yellow box in Three.JS when working with EdgesGeometry, LineSegments, and BoxHelper

Three.js Version: 82 I recently came across an interesting example on the official Three.js website: In this example, I noticed the presence of yellow boxes surrounding the 3D models. Previously, in version 79, I used THREE.EdgesHelper to outline the 3D ...

Navigate to the logout page upon encountering an error during the request

I recently upgraded our application from angular 2 to angular 5 and also made the switch from the deprecated Http module to the new HttpClient. In the previous version of the application, I used the Http-Client to redirect to a specific page in case of er ...

Eliminating the muted attribute does not result in the sound being restored

I am looking to implement a feature where a video loads automatically without sound, but when a user clicks a button labeled "Watch with Sound", the video restarts from the beginning and plays with sound. Below is the JavaScript code: let videoButton = do ...

What is the best approach to send a value to the controller?

How can I pass a value to the child controller using the stateProvider in Angular? This is what I have so far: $stateProvider .state('test', { url: '/test', views: { '': { ...

Organize array by year and month groupings

I'm trying to organize an array of events by year and month. Here is a sample of my data: const events = [ { name: "event 1", year: 2021, month: 1, }, { name: "event 2", year: 2021, month: 9, }, { ...

What is the process of saving a model with @tensorflow/tfjs-node version 2?

I've been struggling with setting up the save handler to save my model. I've scoured through various platforms like stack overflow and GitHub, but haven't had any luck. Help! Any guidance would be greatly appreciated!!! :) Below is a snipp ...

I find myself constantly needing to refresh the page just to trigger my ajax request to update text in my Django

I have a follow button that utilizes ajax functionality. The total number of followers, {{ total_followers }}, increases or decreases correctly upon a click. However, the follow and unfollow buttons only update when I refresh the entire page, which is not ...

Nodejs is failing to write to the log file when running in a production environment

I have been working on recording HTTP requests to a .log file. This is how I create and write to it: const accessLogStream = fs.createWriteStream(path.join(__dirname, 'logger.log'), { flags: 'a' }); and then I write to it using middl ...

Tips for expanding a React class using typescript

Let's consider a basic example: interface BaseProps { name: string; } class BaseClass<P extends BaseProps> extends React.Component<P, void> { } interface SuperProps { } class SuperClass extends BaseClass<SuperProps> { } M ...

What is preventing me from utilizing Omit with AsyncProps in react-select?

My current challenge involves wrapping a custom component called SelectSearchResult around the AsyncSelect component from the library react-select. I want most of the props for my custom component to be similar to those of AsyncSelect, but with some except ...