Cannot read property 'push' of undefined


#1

i try create web app but stuck Post detail Please help me…

home.html

<button full primary padding (click)="openSinglePage(data._links.self[0].href)">READ MORE</button>

home.ts

openSinglePage(url) {
this.navCtrl.push(Postdetail, {
url: url
})
}

Postdetail.ts

export class Postdetail {
  datas: any[];
  postId: number
  judul: any
  Link: any
  gambar: any
  excerpt: any
    comments: any;
  constructor(private navCtrl: NavController, params: NavParams, private http: Http, private Service: PostService) {

    this.http.get(params.data.url + "/?_embed").subscribe(data => {
      this.datas.push(data.json());

      this.http.get(data.json()._links.replies[0].href).subscribe(comment => {
        this.comments = comment.json()
      });

    });

  }

if i Push button get error
Console Eror

Angular 2 is running in the development mode. Call enableProdMode() to enable the production mode.
main.js:224 Native: tried calling StatusBar.styleDefault, but Cordova is not available. Make sure to include cordova.js or run in a device/simulatorcordovaWarn @ main.js:224callCordovaPlugin @ main.js:291(anonymous function) @ main.js:490value @ main.js:563(anonymous function) @ main.js:73235t.invoke @ polyfills.js:3onInvoke @ main.js:82533t.invoke @ polyfills.js:3e.run @ polyfills.js:3(anonymous function) @ polyfills.js:3t.invokeTask @ polyfills.js:3onInvokeTask @ main.js:82524t.invokeTask @ polyfills.js:3e.runTask @ polyfills.js:3i @ polyfills.js:3invoke @ polyfills.js:3
main.js:224 Native: tried calling Splashscreen.hide, but Cordova is not available. Make sure to include cordova.js or run in a device/simulatorcordovaWarn @ main.js:224callCordovaPlugin @ main.js:291(anonymous function) @ main.js:490value @ main.js:563(anonymous function) @ main.js:73236t.invoke @ polyfills.js:3onInvoke @ main.js:82533t.invoke @ polyfills.js:3e.run @ polyfills.js:3(anonymous function) @ polyfills.js:3t.invokeTask @ polyfills.js:3onInvokeTask @ main.js:82524t.invokeTask @ polyfills.js:3e.runTask @ polyfills.js:3i @ polyfills.js:3invoke @ polyfills.js:3
main.js:36086 [Object, Object, Object, Object, Object, Object, Object, Object, Object, Object]
main.js:44203 EXCEPTION: Cannot read property 'push' of undefinedErrorHandler.handleError @ main.js:44203next @ main.js:27556schedulerFn @ main.js:29072SafeSubscriber.__tryOrUnsub @ main.js:35673SafeSubscriber.next @ main.js:35622Subscriber._next @ main.js:35575Subscriber.next @ main.js:35539Subject.next @ main.js:23028EventEmitter.emit @ main.js:29064onError @ main.js:29704onHandleError @ main.js:82554t.handleError @ polyfills.js:3e.runTask @ polyfills.js:3invoke @ polyfills.js:3
main.js:44208 ORIGINAL STACKTRACE:ErrorHandler.handleError @ main.js:44208next @ main.js:27556schedulerFn @ main.js:29072SafeSubscriber.__tryOrUnsub @ main.js:35673SafeSubscriber.next @ main.js:35622Subscriber._next @ main.js:35575Subscriber.next @ main.js:35539Subject.next @ main.js:23028EventEmitter.emit @ main.js:29064onError @ main.js:29704onHandleError @ main.js:82554t.handleError @ polyfills.js:3e.runTask @ polyfills.js:3invoke @ polyfills.js:3
main.js:44209 TypeError: Cannot read property 'push' of undefined
    at SafeSubscriber._next (main.js:23173)
    at SafeSubscriber.__tryOrUnsub (main.js:35673)
    at SafeSubscriber.next (main.js:35622)
    at Subscriber._next (main.js:35575)
    at Subscriber.next (main.js:35539)
    at XMLHttpRequest.onLoad (main.js:46564)
    at t.invokeTask (polyfills.js:3)
    at Object.onInvokeTask (main.js:82524)
    at t.invokeTask (polyfills.js:3)
    at e.runTask (polyfills.js:3)ErrorHandler.handleError @ main.js:44209next @ main.js:27556schedulerFn @ main.js:29072SafeSubscriber.__tryOrUnsub @ main.js:35673SafeSubscriber.next @ main.js:35622Subscriber._next @ main.js:35575Subscriber.next @ main.js:35539Subject.next @ main.js:23028EventEmitter.emit @ main.js:29064onError @ main.js:29704onHandleError @ main.js:82554t.handleError @ polyfills.js:3e.runTask @ polyfills.js:3invoke @ polyfills.js:3
main.js:23173 Uncaught TypeError: Cannot read property 'push' of undefined(…)(anonymous function) @ main.js:23173SafeSubscriber.__tryOrUnsub @ main.js:35673SafeSubscriber.next @ main.js:35622Subscriber._next @ main.js:35575Subscriber.next @ main.js:35539onLoad @ main.js:46564t.invokeTask @ polyfills.js:3onInvokeTask @ main.js:82524t.invokeTask @ polyfills.js:3e.runTask @ polyfills.js:3invoke @ polyfills.js:3

ilink is corect


#2

I think you need to set an initial value do datas

datas: any[] = [];

should work.


#3

thanks you @chrisbenseler its works now