Боковой ящик Telerik-UI в angular2-seed-advanced (устройство Android)

Я пытаюсь заставить это работать, но это дает мне только следующую ошибку. Я сделал почти то же самое для приложения nativescript-groceries, но angular2-seed-advanced имеет несколько другую архитектуру, похоже, это проблема внедрения зависимостей где-то между нативным скриптом и проектом seed и telerik-ui.

Любая помощь приветствуется:

ИСКЛЮЧЕНИЕ: Ошибка в /data/data/com.yourdomain.appname/files/app/app/components/app.component.tns.html:0:0 ИСХОДНОЕ ИСКЛЮЧЕНИЕ: TypeError: Не удается прочитать свойство «android» неопределенного ИСХОДНОГО STACKTRACE: TypeError: невозможно прочитать свойство «android» из undefined в RadSideDrawer.initOldDrawer (/data/data/com.yourdomain.appname/files/app/tns_modules/nativescript-telerik-ui/sidedrawer/sidedrawer.js:91:40) в RadSideDrawer ._createUI (/data/data/com.yourdomain.appname/files/app/tns_modules/nativescript-telerik-ui/sidedrawer/sidedrawer.js:147:18) в RadSideDrawer.View._onContextChanged (/data/data/com. yourdomain.appname/files/app/tns_modules/ui/core/view.js:197:14) в RadSideDrawer.View._onAttached (/data/data/com.yourdomain.appname/files/app/tns_modules/ui/core/ view.js:149:14) в Page.View._addViewCore (/data/data/com.yourdomain.appname/files/app/tns_modules/ui/core/view.js:125:18) в Page.View._addView (/data/data/com.yourdomain.appname/fi les/app/tns_modules/ui/core/view-common.js:952:14) в Page.Object.defineProperty.set [как содержимое] (/data/data/com.yourdomain.appname/files/app/tns_modules/ ui/content-view/content-view.js:19:22) в ViewUtil.insertChild (/data/data/com.yourdomain.appname/files/app/tns_modules/nativescript-angular/view-util.js:56: 28) в ViewUtil.createAndAttach (/data/data/com.yourdomain.appname/files/app/tns_modules/nativescript-angular/view-util.js:103:18) в ViewUtil.createView (/data/data/com. yourdomain.appname/files/app/tns_modules/nativescript-angular/view-util.js:110:25) КОНТЕКСТ ОШИБКИ: [объект Объект]

Вот мои изменения

родной скрипт/package.json

### Added dependency
"nativescript-telerik-ui": "^1.3.1",

родной скрипт/приложение/native.module.ts

...
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 { }

родной скрипт/приложение/страницы/приложение/приложение.component.ts:

...
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);
    ...    

родной скрипт/приложение/приложение/компоненты/app.component.ts

...
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";
  }

}

родной скрипт/приложение/приложение/компоненты/приложение.компонент.tns.html

<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>

родной скрипт/приложение/приложение/компоненты/приложение.компонент.tns.css

.sideStackLayout {
  background-color: white;
}

comment
Привет, разработчик из команды NativeScript. Сегодня мы выпустили нашу последнюю версию 1.4.0 плагина nativescript-telerik-ui, не могли бы вы попробовать и протестировать описанную проблему с последней версией. Здесь вы можете увидеть последние примеры SDK github.com/telerik/nativescript-ui-samples- угловой   -  person Vladimir Amiorkov    schedule 16.09.2016
comment
Привет Владимир. Пробовал 1.4.0, но проблема осталась. Но я понял, что это может быть неправильное место для добавления ящика. @Inject(Page), вероятно, работает только на странице, на которую маршрутизируется через ‹page-router-outlet›, а не в app.component, который содержит ‹page-router-outlet›.   -  person Rob    schedule 20.09.2016
comment
Ну ... перемещение ящика на страницу «О программе» (загружаемую через page-router-outlet) приводит к той же ошибке. На самом деле, даже без изменения about.component.ts и простого добавления ‹RadSideDrawer› в about.component.tns.html уже возникает ошибка.   -  person Rob    schedule 26.09.2016
comment
то же самое с 1.4.1   -  person Rob    schedule 26.09.2016
comment
хорошо, все заработало, кажется, tns livesync не очень хочет синхронизироваться в реальном времени, см. мой собственный ответ   -  person Rob    schedule 27.09.2016


Ответы (1)


Хорошо, все заработало, и я хотел поделиться этим, так как это не совсем просто или особенно хорошо задокументировано...

С выпуском nativescript-telerik-ui 1.4.1 и последней версией 2.0.0 Angular это на самом деле довольно просто.

родной скрипт/package.json

### Added dependency
"nativescript-telerik-ui": "^1.4.1",

родной скрипт/приложение/native.module.ts

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

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

export class NativeModule { }

родной скрипт/приложение/страницы/приложение/приложение.component.ts:

no changes - drawer is supposed to be used per page

родной скрипт/приложение/приложение/компоненты/app.component.ts

no changes - drawer is supposed to be used per page

родной скрипт/приложение/приложение/компоненты/о/о.компонент.тс

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";
  }

}

родной скрипт/приложение/приложение/компоненты/приложение.компонент.tns.html

<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>

родной скрипт/приложение/приложение/компоненты/приложение.компонент.tns.css

.sideStackLayout {
  background-color: white;
}
person Rob    schedule 26.09.2016
comment
Привет, просто хочу сообщить вам, что #drawer в объявлении RadSideDrawer не является обязательным, он остался в некоторых документах NativeScript-UI из предыдущих версий Angular 2 RC. - person Vladimir Amiorkov; 27.09.2016