Ionic 2 Alert - nav.present error


#1

I’m using the Ionic 2 Alert component by the book, and am receiving an error:

TypeError: Attempted to assign to a readonly property. in [d.buttons in AlertCmp@0:1548]
This is pretty annoying since my code seems to be almost exactly dupicated from the examples (simplified for brevity):

export class myPage{
    static get parameters(){
        return [[IonicApp]];
    }

    constructor(app){
        this.app = app;
        this._eventHandler();
    }

    _eventHandler(){
        let nav = this.app.getComponent('nav');
        let a = Alert.create({
            title: "Cool alert.",
            buttons: [
                {
                    text: "Ok",
                    handler: () => {}
                }
            ]
        });
        nav.present(a);
    }
}

This particular version of the code is a more explicit version - i.e. uses full button object definition, etc. I’ve tried many permutations including passing the nav in as a dependency and creating the alert in various ways.

I’m not entirely ruling out that the problem could be elsewhere, but I’m positive that it’s linked with the nav.present() call because when I comment that out everything else fires off without a problem.

Thoughts?


#2

Turns out this was not a problem with any of my code, or even the Alert component. It was actually an update to the platform that caused livereload to cause breakages, which I have no way of explaining how/why. We started noticing these random, readonly property issues across multiple cases, and running the emulator without livereload solved all of them. Will be stepping away from livereload for now.


#3

I found the same thing when simply trying to update an object that was initially declared as part of this. during the Pages constructor.

e.g.

this.objects = [];

later in code this.objects would be updated. Works in serve, and during run on android, however, livereload on iOS emulator threw the same Type error as you mentioned.


#4

Yeah, I haven’t gone back to livereload yet… though with the amount of work being done for all I know it could have started working again. Once I try it and it works, I’ll try to remember to update this.