2
Btw、私はTypescriptとAngular2を初めて使用しています。Typescriptのオブジェクトへのループ
PracticeTestListのオブジェクトを返すサービスがあります。サービスとオブジェクトの宣言を以下に示します。
ここでは、以下に示すように、オブジェクトを読み取るカスタムパイプがあります。
カスタムパイプクラスは、オブジェクトを受けなかったが、 forループにオブジェクトがないオブジェクトとして単線文字列として読み取られます。何故ですか?
オブジェクトをオブジェクトとして、Typescriptで読み取る方法は?
おかげ
サービス
getMyPracticeTest(uid: string){
return this._http.get('http://localhost:49753/RestServiceImpl.svc/getMyPracticeTest/' + uid)
.map(data => {
data.json();
// the console.log(...) line prevents your code from working
// either remove it or add the line below (return ...)
console.log("getMyPracticeTest >>>>>>> ", <PracticeTestList[]>data.json());
return <PracticeTestList[]>data.json();
});
}
オブジェクトの宣言
import { Injectable } from '@angular/core';
@Injectable()
export interface PracticeTestList {
Purchase_ID: number;
User_FK: number;
name: string;
price: number;
resteurant: string;
credit_card_number: string;
purchase_date : any;
Test_Status_FK: number;
child :string;
}
カスタムパイプ
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({name: 'values'})
export class ValuesPipe implements PipeTransform {
transform(value, args:string[]) : any {
let keys = [];
for (let key in value) {
console.log("Key >>>> " + key + " value >>>>> " + value[key]);
keys.push({key: key, value: value[key]});
}
return keys;
}
}
追加されたログのパイプ
Key >>>> 0 value >>>>> [ main.bundle.js:64502:13
Key >>>> 1 value >>>>> { main.bundle.js:64502:13
Key >>>> 2 value >>>>> " main.bundle.js:64502:13
Key >>>> 3 value >>>>> P main.bundle.js:64502:13
Key >>>> 4 value >>>>> u main.bundle.js:64502:13
Key >>>> 5 value >>>>> r main.bundle.js:64502:13
Key >>>> 6 value >>>>> c main.bundle.js:64502:13
Key >>>> 7 value >>>>> h main.bundle.js:64502:13
Key >>>> 8 value >>>>> a main.bundle.js:64502:13
Key >>>> 9 value >>>>> s main.bundle.js:64502:13
Key >>>> 10 value >>>>> e main.bundle.js:64502:13
Key >>>> 11 value >>>>> _ main.bundle.js:64502:13
Key >>>> 12 value >>>>> I main.bundle.js:64502:13
Key >>>> 13 value >>>>> D main.bundle.js:64502:13
Key >>>> 14 value >>>>> " main.bundle.js:64502:13
Key >>>> 15 value >>>>> : main.bundle.js:64502:13
Key >>>> 16 value >>>>> 1 main.bundle.js:64502:13
Key >>>> 17 value >>>>> , main.bundle.js:64502:13
Key >>>> 18 value >>>>> "
を追加しましたHTMLコード
<table class="table" *ngIf="myPurchaseItems">
<tr *ngFor="let entry of myPurchaseItems | values">
<td>Key: {{entry.key}}, value: {{entry.value}}</td>
</tr>
</table>
[オブジェクトオブジェクト]などと似ていますか? – chrispy
あなたはあなたのパイプの中にあるconsole.log(値)のログを提供できますか? – chrispy
テンプレートのソースを投稿できますか? –