nativescript-angular: RadSideDrawer Showing an error like Cannot Read property 'sideDrawer' of undefined.
app.component.ts
`import { FireBaseService } from "./services";
import { Component, Injectable, ViewChild, ChangeDetectorRef } from "@angular/core";
import { RadSideDrawerComponent, SideDrawerType } from "nativescript-telerik-ui/sidedrawer/angular";
@Injectable()
@Component({
selector: "main",
template: "<page-router-outlet></page-router-outlet>",
})
export class AppComponent {
@ViewChild(RadSideDrawerComponent)
public drawerComponent: RadSideDrawerComponent;
public drawer: SideDrawerType;
public pages: Array<Object>
constructor(private firebaseService: FireBaseService,
private _changeDetectionRef: ChangeDetectorRef) {
this.pages = [
{ name: "Home" },
{ name: "About" },
{ name: "Contact" }
];
}
ngOnInit() {
this.firebaseService.initFirebase().then(
(instance) => {
this.firebaseService.subscribeNotifications();
console.log("firebase.init done");
},
(error) => {
console.log("firebase.init error: " + error);
}
);
console.log("Drawer COmoponent is", JSON.stringify(this.drawerComponent));
}
ngAfterViewInit() {
this.drawer = this.drawerComponent.sideDrawer;
this._changeDetectionRef.detectChanges();
}
public openDrawer() {
this.drawer.toggleDrawerState();
}
}
`
app.component.html
`import { Component, Injectable, ViewChild, ChangeDetectorRef } from "@angular/core";
import { RadSideDrawerComponent, SideDrawerType } from "nativescript-telerik-ui/sidedrawer/angular";
@Injectable()
@Component({
selector: "main",
template: "<page-router-outlet></page-router-outlet>",
})
export class AppComponent {
@ViewChild(RadSideDrawerComponent)
public drawerComponent: RadSideDrawerComponent;
public drawer: SideDrawerType;
public pages: Array<Object>
constructor(private firebaseService: FireBaseService,
private _changeDetectionRef: ChangeDetectorRef) {
this.pages = [
{ name: "Home" },
{ name: "About" },
{ name: "Contact" }
];
}
ngAfterViewInit() {
this.drawer = this.drawerComponent.sideDrawer;
this._changeDetectionRef.detectChanges();
}
public openDrawer() {
this.drawer.toggleDrawerState();
}
}
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 23
I removed and re-added the platform, and that got rid of the problem.
I’ve found this is a basic approach to handling unexpected errors.
@JaganJonnala That is not an acceptable answer for an already in-progress app.
@taibuiSW That worked for me too… Issue with the post/pre install of the plugin?
it showing an error like
I noticed the same thing also - this has come to make me wonder if this should be looked at by NS or get some feedback from NS as to what is the root cause.
@taibuiSW that worked for me also. It seems like there needs to be a forced regeneration.