首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Telerik-UI侧抽屉在angular2-种子先进(Android设备)

Telerik-UI侧抽屉在angular2-种子先进(Android设备)
EN

Stack Overflow用户
提问于 2016-09-14 15:23:36
回答 1查看 764关注 0票数 1

我试着让它起作用,但它只给了我以下的错误。我对nativescript-groceries应用程序做了几乎相同的事情,但是angular2种子高级程序的体系结构有点不同,似乎是一个依赖注入问题,介于本地文本和种子项目以及telerik之间。

如有任何帮助,我们将不胜感激:

异常: /data/data/com.yourdomain.appname/files/app/app/components/app.component.tns.html:0:0原始异常中的错误: TypeError:无法读取未定义的原始STACKTRACE的属性'android‘:TypeError:无法读取未定义的RadSideDrawer.initOldDrawer RadSideDrawer._的属性'android’(/data/data/com.yourdomain.appname/files/app/tns_modules/nativescript-telerik-ui/sidedrawer/sidedrawer.js:147:18) at RadSideDrawer.View._onContextChanged (/data/data/com.yourdomain.appname/files/app/tns_modules/ui/core/view.js:197:14) at RadSideDrawer.View._onAttached (/data/data/com.yourdomain.appname/files/app/tns_modules/ui/core/view.js:149:14(/data/data/com.yourdomain.appname/files/app/tns_modules/ui/core/view.js:125:18) at Page.View._addView (/data/data/com.yourdomain.appname/files/app/tns_modules/ui/core/view-common.js:952:14) at Page.Object.defineProperty.set as content at ViewUtil.insertChild (/data/data/com.yourdomain.appname/files/app/tns_modules/nativescript-angular/view-util.js:56:28) at ViewUtil.createAndAttach (/data/data/com.yourdomain.appname/files/app/tns_modules/nativescript-angular/view-util.js:103:18) at ViewUtil.createView (/data/data/com.yourdomain.appname/files/app/tns_modules/nativescript-angular/view-util.js:110:25)错误上下文:对象对象

这是我的零钱

nativescript/package.json

代码语言:javascript
复制
### Added dependency
"nativescript-telerik-ui": "^1.3.1",

nativescript/app/native.module.ts

代码语言:javascript
复制
...
import {SIDEDRAWER_PROVIDERS} from 'nativescript-telerik-ui/sidedrawer/angular';
... 
@NgModule({
  ...
  providers: [
    NS_ANALYTICS_PROVIDERS,
    ### Added sidedrawer providers
    SIDEDRAWER_PROVIDERS,
    { provide: RouterExtensions, useClass: TNSRouterExtensions }
  ],
  ...
})

export class NativeModule { }

nativescript/app/page/app/app.Component.ts:

代码语言:javascript
复制
...
import {Inject, ChangeDetectorRef} from '@angular/core';
...
import {Page} from 'ui/page';
...
export class NSAppComponent extends AppComponent {
  constructor(
    @Inject(Page) private _page: Page,
    private _changeDetectionRef: ChangeDetectorRef,
    @Inject(AnalyticsService) public analytics: AnalyticsService,
    @Inject(LogService) private log: LogService,
    @Inject(Store) private store: Store<any>,
    @Inject(Router) private router: Router)
  {
    // ### ADDED Page and ChangeDetectionRef
    super(_page, _changeDetectionRef, analytics, log);
    ...    

nativescript/app/app/components/app.component.ts

代码语言:javascript
复制
...
import {ViewChild, ChangeDetectorRef, ChangeDetectionStrategy, AfterViewInit} from '@angular/core';
... 
import {
  SIDEDRAWER_DIRECTIVES,
  RadSideDrawerComponent,
  SideDrawerType
} from 'nativescript-telerik-ui/sidedrawer/angular';
import {DrawerTransitionBase, PushTransition} from 'nativescript-telerik-ui/sidedrawer';
import {Page} from 'ui/page';
...
@BaseComponent(
  {
    moduleId       : module.id,
    selector       : 'sd-app',
    templateUrl    : 'app.component.html',
    directives     : [SIDEDRAWER_DIRECTIVES],
    changeDetection: ChangeDetectionStrategy.Default // Everything else uses OnPush
  }
)
export class AppComponent implements AfterViewInit {
  private _currentNotification: string;
  private _sideDrawerTransition: DrawerTransitionBase;

  @ViewChild(RadSideDrawerComponent) public drawerComponent: RadSideDrawerComponent;
  private drawer: SideDrawerType;

  constructor(
    private page: Page,
    private changeDetectionRef: ChangeDetectorRef,
    public analytics: AnalyticsService,
    public logger: LogService)
  {
    logger.debug(`Config env: ${Config.ENVIRONMENT().ENV}`);
    this.page.on("loaded", this.onLoaded, this);
  }

  ngAfterViewInit() {
    this.drawer = this.drawerComponent.sideDrawer;
    this.changeDetectionRef.detectChanges();
  }


  public onLoaded(args) {
    this._sideDrawerTransition = new PushTransition();
  }

  public get sideDrawerTransition(): DrawerTransitionBase {
    return this._sideDrawerTransition;
  }

  public get currentNotification(): string {
    return this._currentNotification;
  }

  public openDrawer() {
    this.drawer.showDrawer();
  }

  public onDrawerOpening() {
    console.log("Drawer opening");
    this._currentNotification = "Drawer opening";
  }

  public onDrawerOpened() {
    console.log("Drawer opened");
    this._currentNotification = "Drawer opened";
  }

  public onDrawerClosing() {
    console.log("Drawer closing");
    this._currentNotification = "Drawer closing";
  }

  public onDrawerClosed() {
    console.log("Drawer closed");
    this._currentNotification = "Drawer closed";
  }

}

nativescript/app/app/components/app.component.tns.html

代码语言:javascript
复制
<RadSideDrawer #drawer>
  <StackLayout tkDrawerContent class="sideStackLayout">
    <StackLayout class="sideTitleStackLayout">
      <Label text="Navigation Menu"></Label>
    </StackLayout>
    <StackLayout class="sideStackLayout">
      <Label text="MenuItemA" ></Label>
      <Label text="MenuItemB" ></Label>
      <Label text="MenuItemC" ></Label>
    </StackLayout>
  </StackLayout>
  <StackLayout tkMainContent>
    <!-- nested original content in Drawer -->
    <ActionBar title="Test" class="action-bar">
      <ActionItem ios.position="right" android.position="popup">
        <Button [text]="'MENU' | translate" (tap)=openDrawer() class="action-btn"></Button>
      </ActionItem>
      <ActionItem nsRouterLink="/about" ios.position="right" android.position="popup">
        <Button [text]="'ABOUT' | translate" class="action-btn"></Button>
      </ActionItem>
    </ActionBar>
    <StackLayout class="container">
      <lang-switcher></lang-switcher>
      <ScrollView>
        <page-router-outlet></page-router-outlet>
      </ScrollView>
    </StackLayout>
  </StackLayout>

nativescript/app/app/components/app.component.tns.css

代码语言:javascript
复制
.sideStackLayout {
  background-color: white;
}
EN

回答 1

Stack Overflow用户

发布于 2016-09-26 23:10:38

好的,让它开始工作,并想要分享这个,因为它不是非常简单或特别清楚的文件.

通过发布本地文本-telerik 1.4.1和角的最终2.0.0版本,这实际上是相当容易的。

nativescript/package.json

代码语言:javascript
复制
### Added dependency
"nativescript-telerik-ui": "^1.4.1",

nativescript/app/native.module.ts

代码语言:javascript
复制
...
import { SIDEDRAWER_DIRECTIVES } from 'nativescript-telerik-ui/sidedrawer/angular';

... 
@NgModule({
  ...
  declarations: [
    SIDEDRAWER_DIRECTIVES, ### allows usage of <RadSideDrawer> in pages
    HomeComponent,
    AboutComponent
  ],
  ...
})

export class NativeModule { }

nativescript/app/page/app/app.Component.ts:

代码语言:javascript
复制
no changes - drawer is supposed to be used per page

nativescript/app/app/components/app.component.ts

代码语言:javascript
复制
no changes - drawer is supposed to be used per page

nativescript/app/app/components/about/about.component.ts

代码语言:javascript
复制
import {ViewChild, ChangeDetectorRef, Inject} from '@angular/core';
... 
import {RadSideDrawerComponent, SideDrawerType } from 'nativescript-telerik-ui/sidedrawer/angular';
import {DrawerTransitionBase, PushTransition} from 'nativescript-telerik-ui/sidedrawer';
import {Page} from 'ui/page';
...
export class AboutComponent {
  private _currentNotification: string;
  private _sideDrawerTransition: DrawerTransitionBase;

  @ViewChild(RadSideDrawerComponent) public drawerComponent: RadSideDrawerComponent;
  private drawer: SideDrawerType;

  constructor(
    private page: Page,
    private changeDetectionRef: ChangeDetectorRef )
  {
    this.page.on("loaded", this.onLoaded, this);
  }

  ngAfterViewInit() {
    this.drawer = this.drawerComponent.sideDrawer;
    this.changeDetectionRef.detectChanges();
  }


  public onLoaded(args) {
    this._sideDrawerTransition = new PushTransition();
  }

  public get sideDrawerTransition(): DrawerTransitionBase {
    return this._sideDrawerTransition;
  }

  public get currentNotification(): string {
    return this._currentNotification;
  }

  public openDrawer() {
    this.drawer.showDrawer();
  }

  public onDrawerOpening() {
    console.log("Drawer opening");
    this._currentNotification = "Drawer opening";
  }

  public onDrawerOpened() {
    console.log("Drawer opened");
    this._currentNotification = "Drawer opened";
  }

  public onDrawerClosing() {
    console.log("Drawer closing");
    this._currentNotification = "Drawer closing";
  }

  public onDrawerClosed() {
    console.log("Drawer closed");
    this._currentNotification = "Drawer closed";
  }

}

nativescript/app/app/components/app.component.tns.html

代码语言:javascript
复制
<RadSideDrawer #drawer
           (drawerOpening)="onDrawerOpening()"
           (drawerOpened)="onDrawerOpened()"
           (drawerClosing)="onDrawerClosing()"
           (drawerClosed)="onDrawerClosed()"
           [transition]="sideDrawerTransition">

  <StackLayout tkDrawerContent class="sideStackLayout">
      <Label text="MenuItemA" ></Label>
      <Label text="MenuItemB" ></Label>
      <Label text="MenuItemC" ></Label>
  </StackLayout>

  <StackLayout tkMainContent>
    <!-- nested original content in Drawer -->
    <ActionBar title="Test" class="action-bar">
      <ActionItem ios.position="right" (tap)=openDrawer() android.position="popup">
        <Button [text]="'MENU' | translate" class="action-btn"></Button>
      </ActionItem>
      <ActionItem nsRouterLink="/about" ios.position="right" android.position="popup">
        <Button [text]="'ABOUT' | translate" class="action-btn"></Button>
      </ActionItem>
    </ActionBar>
    <StackLayout>
      <Label text="Angular 2 Seed Advanced is ...
      ...
    </StackLayout>
  </StackLayout>

nativescript/app/app/components/app.component.tns.css

代码语言:javascript
复制
.sideStackLayout {
  background-color: white;
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39494215

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档