AngularJS JSON 파일 연동

2018. 6. 13. 07:02서버 프로그래밍

안드로이드, 아이폰 앱에서 사용하던 SQLite 데이터베이스를 AngularJS에서 연동하려니 꽤나 번거롭고 제약이 많다.

Firebase라도 써보려고 했는데, Only 프론트엔드 개발자라면 모를까, 나같은 백엔드 개발까지 하는 개발자에게는 너무 허접해서 못봐주겠다.

그래서 그냥 SQLite 데이터베이스의 데이터를 JSON export 해서 사용하기로 했다.


http://www.encodedna.com/angular/read-an-external-json-file-in-angular-4-and-convert-data-to-table.htm


export class AppComponent {
  title = 'JSON to Table Example';
  constructor (private httpService: HttpClient) { }
  arrBirds: string [];

  ngOnInit () {
    this.httpService.get('./assets/birds.json').subscribe(
      data => {
        this.arrBirds = data as string [];	 // FILL THE ARRAY WITH DATA.
        //  console.log(this.arrBirds[1]);
      },
      (err: HttpErrorResponse) => {
        console.log (err.message);
      }
    );
  }
}