0
サービスを呼び出し、データを返すコンポーネントがあります(図を参照)。データはHTMLページに表示されません。私は何を取りこぼしたか?ので、任意のヘルプは大幅にサービスから返されたデータが角2のコンポーネントに表示されない
ルートコンポーネントを理解されるであろう角度2に新規roots
配列は配列の配列として戻って来ているが、データは正確であると私はHTMLが正しいと信じても
。
export class RootsComponent implements OnInit {
private baseRootEndpoint: string = 'http://localhost:59534/api/admin';
private isUploadBtn: boolean = true;
private dbops: number = 0;
private msg: string = '';
private dataForm: FormGroup;
private imageData;
private contentType;
private fileLength;
public roots: Root[];
private isLoading = true;
@Input() root: Root;
constructor(private http: Http, private _rootService : RootService, fb:FormBuilder) {
}
ngOnInit() {
this.roots = [];
this.getRoots();
}
//call the service and bring back a list of roots
getRoots() {
debugger;
var me = this;
this._rootService.get(this.baseRootEndpoint).subscribe(
data => me.roots.push(JSON.parse(data._body)),
error => me.msg = error
);
this.isLoading = false;
}
}
//simple service
@Injectable()
export class RootService {
constructor(private _http: Http) { }
get(url: string): Observable<any> {
debugger;
return this._http.get(url);
}
}
<div class="container-fluid">
<div class="row">
<div class="header">
<h4 class="title"> Roots</h4>
</div>
<div class="col-lg-10 col-lg-offset-1" *ngIf="!isLoading">
<table>
<thead>
<tr>
<th>Root Name</th>
<th>Root</th>
<th>Definition</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let root of roots[0]" let id="index">
<td>{{root.DescriptiveName}}</td>
<td><img src="{{root.Root}}" name="rootImage" /></td>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
サービスを共有できますか? – Antikhippe
クイックコード形式と – phuzi
これはサービスですが、私はその問題を信じていませんが、正しいデータが返されます。 '@ angular/http'から{Http、Response、Headers、RequestOptions}をインポートします。 'rxjs/Observable'から{Observable}をインポートします。 'rxjs/add/operator/map'をインポートします。 'rxjs/add/operator/do'をインポートします。 'rxjs/add/operator/catch'をインポートします。 {ルート}から '../root'をインポートします。 @Injectable() 輸出クラスRootService { コンストラクタ(プライベート_HTTP:HTTP){} GET(URL:文字列):観察可能 { デバッガ。 これを返す._http.get(url); } –
jamesT