{"action":"opened","issue":{"url":"https://api.github.com/repos/gilf/angular2-indexeddb/issues/45","repository_url":"https://api.github.com/repos/gilf/angular2-indexeddb","labels_url":"https://api.github.com/repos/gilf/angular2-indexeddb/issues/45/labels{/name}","comments_url":"https://api.github.com/repos/gilf/angular2-indexeddb/issues/45/comments","events_url":"https://api.github.com/repos/gilf/angular2-indexeddb/issues/45/events","html_url":"https://github.com/gilf/angular2-indexeddb/issues/45","id":265497539,"number":45,"title":"How to use \"db.getAll\" in ngOnInit()?","user":{"login":"arzek","id":18478070,"avatar_url":"https://avatars0.githubusercontent.com/u/18478070?v=4","gravatar_id":"","url":"https://api.github.com/users/arzek","html_url":"https://github.com/arzek","followers_url":"https://api.github.com/users/arzek/followers","following_url":"https://api.github.com/users/arzek/following{/other_user}","gists_url":"https://api.github.com/users/arzek/gists{/gist_id}","starred_url":"https://api.github.com/users/arzek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arzek/subscriptions","organizations_url":"https://api.github.com/users/arzek/orgs","repos_url":"https://api.github.com/users/arzek/repos","events_url":"https://api.github.com/users/arzek/events{/privacy}","received_events_url":"https://api.github.com/users/arzek/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-10-14T15:05:21Z","updated_at":"2017-10-14T15:05:21Z","closed_at":null,"author_association":"NONE","body":"Hi, how to use \"db.getAll\" in ngOnInit()?\r\nMy code:\r\n```\r\nimport {Component, OnInit} from '@angular/core';\r\nimport {AngularIndexedDB} from 'angular2-indexeddb';\r\n\r\n\r\n@Component({\r\n  selector: 'app-root',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\nexport class AppComponent implements OnInit {\r\n  new_item: String = '';\r\n  data: any[] = [];\r\n\r\n  db: any = null;\r\n  indexedDB: any = window.indexedDB;\r\n\r\n  constructor() {\r\n    this.db = new AngularIndexedDB('MyDb', 1);\r\n\r\n    this.db.openDatabase(1, (evt) => {\r\n      evt.currentTarget.result.createObjectStore(\r\n        'item', { keyPath: 'id', autoIncrement: true });\r\n    });\r\n  }\r\n\r\n\r\n  ngOnInit(): void {\r\n    // This error \"You need to use the createStore function to create a database before you query it!]\"\r\n    this.db.getAll('item').then((item) => {\r\n    console.log(item);\r\n}, (error) => {\r\n    console.log(error);\r\n});\r\n  }\r\n  addItem(): void {\r\n    this.db.add('item', { text: this.new_item }).then((evt) => {\r\n\r\n      this.data.push({text: this.new_item, id: evt.key});\r\n      this.new_item = '';\r\n    }, (error) => {\r\n      console.log(error);\r\n    });\r\n  }\r\n  deleteItem(id: number): void {\r\n    console.log(id);\r\n    this.db.delete('item', id).then(() => {\r\n      this.data  = this.data.filter( item => (item.id !== id));\r\n    }, (error) => {\r\n      console.log(error);\r\n    });\r\n\r\n  }\r\n  \r\n}\r\n\r\n`"}}
{"actor":{"display_login":"arzek"}}