私は自分の結果を反復しようとしていngFor
ます-Angular 1のように直感的ではありません.私は次のことをしています:
search.service.ts
import {Injectable} from 'angular2/core';
import {Http, HTTP_PROVIDERS, Response} from 'angular2/http';
import 'rxjs/add/operator/map';
@Injectable()
export class SearchService {
constructor( private _http: Http ) {
}
DoGeneralSearch(s){
return this._http.get('http://localhost:6000/search?q=' + s)
.map((res:Response) => res.json())
}
}
typeahead.ts
import {Component, Input, OnChanges} from "angular2/core";
import {SearchService} from "../../../services/search.service";
@Component({
selector: "typeahead",
providers: [SearchService],
template : `
<div>{{searchSvc | async | json}}</div>
<div id="typeaheadRooms" *ngIf="searchSvc">
<div class="typeaheadRowRooms" *ngFor="#item of searchSvc?.rooms">
<div class="typeaheadRoomTitle">{{item.name}}}</div>
</div>
<div class="typeaheadRowRooms" *ngFor="#item of searchSvc?.colors">
<div class="typeaheadRoomTitle">{{item.name}}}</div>
</div>
`,
})
export class TypeaheadComponent implements OnChanges {
@Input() txt: string;
display = false;
ngOnChanges(changes: {[propName: string]: SimpleChange}) {
var search = changes['txt'].currentValue;
if(search.length > 2) {
this.display = true;
this.searchSvc = this._searchService.DoGeneralSearch(search);
}
else
{
this.display = false;
}
}
constructor(private _searchService: SearchService) {}
}
json の典型的な結果:
{
"max":20,
"queryString":"chem",
"rooms":[
{
"name":"Lima"
},
{
"name":"Delta"
}
],
"colors":[
{
"name":"Red"
},
{
"name":"Lime"
}
]
}
何が起こっていますか ?いいから{{searchSvc | async | json}}
結果見せろよ しかしngFor
:いいえ:(
手がかりはありますか?前もって感謝します !!!