如何添加侧抽屉? [Nativescript + Angular]

时间:2017-02-16 19:34:26

标签: android angularjs nativescript angular2-nativescript

在主模块中我添加了这个:

import {SIDEDRAWER_DIRECTIVES} from "nativescript-telerik-ui/sidedrawer/angular";
...
declarations: [
        SIDEDRAWER_DIRECTIVES,
        AppComponent,
        ...AppComponents
]

app.component.html的xml部分:

<RadSideDrawer [drawerLocation]="currentLocation" tkExampleTitle tkToggleNavButton>
    <StackLayout tkDrawerContent class="sideStackLayout">
        <StackLayout class="sideTitleStackLayout">
            <Label text="Navigation Menu"></Label>
        </StackLayout>
        <StackLayout class="sideStackLayout">
            <Label text="Primary" class="sideLabel sideLightGrayLabel"></Label>
            <Label text="Social" class="sideLabel"></Label>
            <Label text="Promotions" class="sideLabel"></Label>
            <Label text="Labels" class="sideLabel sideLightGrayLabel"></Label>
            <Label text="Important" class="sideLabel"></Label>
            <Label text="Starred" class="sideLabel"></Label>
            <Label text="Sent Mail" class="sideLabel"></Label>
            <Label text="Drafts" class="sideLabel"></Label>
        </StackLayout>
    </StackLayout>
    <StackLayout tkMainContent>
        <Label [text]="mainContentText" textWrap="true" class="drawerContentText"></Label>
        <Button text="OPEN DRAWER" (tap)=openDrawer()></Button>
    </StackLayout>
</RadSideDrawer>

当我尝试运行它时,我收到错误:

  

“主”线程上发生了未被捕获的异常。   com.tns.NativeScriptException:调用js方法onCreateView失败

     

TypeError:无法读取未定义文件的属性'android':   “文件:///data/data/org.nativescript.nativescript/files/app/tns_modules/nativescript-telerik-ui/sidedrawer/sidedrawer.js,   line:91,column:39

     

StackTrace:Frame:function:'RadSideDrawer.initOldDrawer',   文件: '文件:///data/data/org.nativescript.nativescript/files/app/tns_modules/nativescript-telerik-ui/sidedrawer/sidedrawer.js',   line:91,column:40 Frame:function:'RadSideDrawer._createUI',   文件: '文件:///data/data/org.nativescript.nativescript/files/app/tns_modules/nativescript-telerik-ui/sidedrawer/sidedrawer.js',   line:147,column:18 Frame:function:'View._onContextChanged',   文件: '文件:///data/data/org.nativescript.nativescript/files/app/tns_modules/ui/core/view.js',   line:202,column:14 Frame:function:'View._onAttached',   文件: '文件:///data/data/org.nativescript.nativescript/files/app/tns_modules/ui/core/view.js',   line:1

任何人都知道什么是问题?

2 个答案:

答案 0 :(得分:1)

  • 进行此导入:

import { NativeScriptUISideDrawerModule } from 'nativescript-telerik-ui/sidedrawer/angular';

  • 将其添加到您的导入中:

imports: [ NativeScriptUISideDrawerModule, ... ]

现在,您的侧抽屉应该可以正常工作。

答案 1 :(得分:0)

解决此类问题的更快方法是使用NativeScript Sidekick。选择创建新项目。其中一个模板具有SideDrawer。