Currently, I am in the process of setting up a basic example of push notifications on Android using Nativescript and Typescript. Although my code may seem a bit messy, I am struggling with properly rewriting "var Observable = require("data/observable");" and "viewModel" in Typescript. The code structure is based on the following example:
import { Component } from "@angular/core";
import * as pushPlugin from "nativescript-push-notifications";
var Observable = require("data/observable");
@Component({
selector: "my-app",
template: `
<ActionBar title="My App" icon="" class="action-bar">
</ActionBar>
<StackLayout>
<Label text="Tap the button to trigger the register function." textWrap="true" class=""></Label>
<Button text="REGISTER" (tap)="registerTap()" ></Button>
<label text="Your device id/token:" textWrap="true" ></label>
<TextView text="{{ registrationId }}" class="title" textWrap="true"></TextView>
<Label text="{{ message }}" class="message" textWrap="true" ></Label>
</StackLayout> `
})
export class AppComponent {
viewModel = new Observable.Observable({
registrationId: ""
});
pageLoaded(args) {
var page = args.object;
page.bindingContext = this.viewModel;
}
registerTap (args) {
// Code for registering and handling push notifications
}
}
Upon clicking the register button, an error occurs:
TypeError: "Cannot read property 'set' of undefined" I'm still learning about Typescript and how to handle notifications properly. Any guidance would be greatly appreciated.
Thank you for your assistance