错误的屏幕截图:
.ts文件代码(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); // the user's search value
params.set('action', 'opensearch');
params.set('format', 'json');
params.set('callback', 'JSONP_CALLBACK');
// TODO: Add error handling
return this.jsonp
.get( ebayURL, { search: params })
.map(request => <string[]> request.json()[1]);
}
}
我认为可能是导致该错误(.SearchDisplay.component.html)的.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>
问题背景:我正在尝试为基本上是eBay克隆的网站创建搜索栏。
原始代码来自Wikipedia示例搜索栏,但我想将其更改为从ebay提取数据(或仅创建一个本地搜索栏,仅包含单词“ apple”和“ car”)。
在这个问题中发布了指向punker /全压缩项目文件的链接:
JSONP_PROVIDERS
在引导程序或更高级别的组件中,您可能缺少必须在更高级别注入的提供程序。
阅读有关JSONP_PROVIDERS的更多信息
引导应用程序时,应将JSONP_PROVIDERS包含在组件的注入器中或根注入器中。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句