【发布时间】:2017-02-06 22:33:31
【问题描述】:
我正在尝试在本机脚本中创建示例应用程序。我通过引用http://docs.telerik.com/devtools/nativescript-ui/Controls/Angular/SideDrawer/getting-started 以下列方式将RadSideDrawer 用于sidemenu:
<RadSideDrawer [transition]="RevealTransition" #drawer>
<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>
<GridLayout rows="*">
<page-router-outlet ></page-router-outlet>
<ActivityIndicator #activityIndicator horizontalAlignment="center" verticalAlignment="center" width="100" height="100" row="0"></ActivityIndicator>
</GridLayout>
</StackLayout>
</RadSideDrawer>
在我的 app.component.ts 中,我给出了:
import {RadSideDrawer} from "nativescript-telerik-ui/sidedrawer";
@ViewChild("drawer") drawer : ElementRef;
和
public toggleDrawer(){
let drawer = <RadSideDrawer>this.drawer.nativeElement;
drawer.toggleDrawerState();
}
问题是,每当我尝试执行 toggleDrawer() 时,都会出现错误:
drawer.toggleDrawerState not a function.
可能出了什么问题?我将 this.drawer 作为 [object Object] 并将 this.drawer.nativeElement 作为 ProxyViewContainer(5),这意味着它正在识别元素,但无法调用 toggleDrawerState();
现在样式也变形了,它现在在主视图中列出了 tkDrawerContent,我无法看到我在 tkMainContent 中指定的原始页面内容。
【问题讨论】:
-
抱歉,您从哪里获得
.nativeElement,因为我在 API 参考中的任何地方都没有看到它 -
查看 nativescript 教程 docs.nativescript.org/tutorial/ng-chapter-4 中的第 4 章。我正在使用此方法获取其他元素,只有 RadSideDrawer 有问题。
-
它是ElementRef中的一个属性
标签: nativescript angular2-nativescript nativescript-telerik-ui