我是nativescript angular2的新手。到目前爲止,我遵循文檔和 與列表視圖做靜態數據。如何獲得angular2 nativescript中的本地json文件路徑
我把我的json文件放在
app/utils/countries.json
。我不知道如何獲得本地文件路徑來解析關於這個json.Need建議。
下面我已經發布了帶有靜態數據的listview代碼。
打字稿:
import { Component, ElementRef, OnInit, ViewChild } from "@angular/core";
@Component({
selector: "ns-app",
templateUrl: "app.component.html",
})
export class AppComponent implements OnInit {
arrList: Array<Object> = [];
ngOnInit() {
this.arrList.push({ name: "India" });
this.arrList.push({ name: "Sri Lanka" });
}
}
HTML:
<page-router-outlet></page-router-outlet>
<GridLayout>
<ListView [items]="arrList" class="small-spacing">
<ng-template let-item="item">
<Label [text]="item.name" class="medium-spacing"></Label>
</ng-template>
</ListView>
</GridLayout>
countries.json:(APP/utils的/ countries.json):
{
"countries": [
{"id":1,"name":"india"},
{"id":2,"name":"Sri Lanka"}
]
}
您選擇想要導入,你有你'應用程序/ utils'文件夾內的JSON文件? – mast3rd3mon
@ mast3rd3mon yes。我需要解析位於app/utils/countries.json這個目錄下的countries.json文件。 – Steve