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