xml code screenshotError screenshotI'm facing an issue where I am trying to bind a label with my code and set its text, but every time I run the code, I get an error message saying 'Cannot set property 'text' of undefined'. I have tried multiple solutions, imported all necessary modules, but the error persists. Any help in resolving this issue would be greatly appreciated.
Here is the code snippet:
import { EventData, Observable } from "data/observable";
import { ObservableArray } from "data/observable-array";
import { Page} from "tns-core-modules/ui/page";
import { GridItemEventData } from "nativescript-grid-view";
import { veriables } from "~/veriables";
import { Button } from "tns-core-modules/ui/button";
import { Label } from "tns-core-modules/ui/label";
let viewModel: Observable = new Observable();
let txtlbl : Label;
export function pageLoaded(args: EventData) {
const page = <Page>args.object;
const items = new ObservableArray();
var myveriable = veriables.getInstance()
const label = <Label>page.getViewById("lbl");
label.text = "NativeScript is Awesome";
var NumberOnelist : number[] = new Array();
var NumberTwolist : number[] = new Array();
var NumberOfQuestions :number;
var Anslist : number[] = new Array();
var Operator : string;
NumberOnelist = myveriable.NumberOneArraylist;
NumberTwolist = myveriable.NumberTwoArraylist;
NumberOfQuestions = myveriable.NumberofQuestions;
Anslist = myveriable.AnswerArrayList;
Operator = myveriable.Operator;
for (let loop = 0; loop <NumberOfQuestions; loop++) {
items.push(NumberOfQuestions);
}
viewModel = new Observable();
viewModel.set("items", items);
page.bindingContext = viewModel;
}
export function gridViewItemTap(args: GridItemEventData) {
console.log("tap index " + args.index.toString());
}
export function gridViewItemLoading(args: GridItemEventData) {
console.log("item loading " + args.index.toString());
}
export function gridViewLoadMoreItems(args: EventData) {
console.log("load more items");
}