我對本地腳本很陌生,因爲我正在學習實現導航抽屜,我只是以一些錯誤而告終。RadSideDrawer not working Nativescript angular 2
register.html
<ActionBar title="Custom Title">
<ActionItem ios.systemIcon="9" android.systemIcon="ic_menu_share_holo_light" (tap)="openDrawer()"></ActionItem>
</ActionBar>
<RadSideDrawer #drawer>
<template drawerSide>
<StackLayout class="p bgc-white">
<ListView row="1">
<template let-item="item" let-i="index">
<StackLayout>
<Label text="WWW" class="page-name" ></Label>
</StackLayout>
</template>
</ListView>
</StackLayout>
</template>
<template drawerMain>
<StackLayout class="m">
<user-list></user-list>
</StackLayout>
</template>
</RadSideDrawer>
register.component.ts
import { Component,OnInit,ViewChild,ChangeDetectorRef } from "@angular/core";
import {RadSideDrawerComponent, SideDrawerType} from 'nativescript-telerik-ui/sidedrawer/angular';
@Component({
selector: "register",
templateUrl :"./pages/register/register.html"
})
export class RegisterComponent
{
@ViewChild(RadSideDrawerComponent) public drawerComponent: RadSideDrawerComponent;
private drawer: SideDrawerType;
constructor (private _changeDetectionRef: ChangeDetectorRef) {
}
ngAfterViewInit() {
console.log(" FFFFF");
this.drawer = this.drawerComponent.sideDrawer;
this._changeDetectionRef.detectChanges();
}
public openDrawer()
{
this.drawer.toggleDrawerState();
}
}
以下是我得到的日誌
promiseReactionJob @ [本地代碼] CONSOLE ERROR file:///app/tns_modules/@angular/core/bundles/core.umd.js:3481:36:錯誤內容:
CONSOLE ERROR file:/// app/tns_modules/@ angular/core /bundles/core.umd.js:3482:36:[object Object]
CONSOLE ERROR file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:344: 22:錯誤:錯誤:0:0造成的:undefined不是一個對象(評估'this.drawerComponent.sideDrawer')
您可以從''標記刪除'#drawer'。而不是它與你的問題有關,但爲了幫助你的IDE,你可以讓你的類實現'AfterViewInit'。 –