RadSideDrawer integration
Anyone succeeded in integrating RadSideDrawer with nativescript-angular, (I’ve tried everything here in terms of general setup: https://github.com/tjvantoll/nativescript-template-drawer)… just doesn’t display anything.
component:
import {Component} from 'angular2/core';
import {registerElement} from 'nativescript-angular/element-registry';
registerElement('Drawer', () => require('nativescript-telerik-ui/sidedrawer'));
@Component({
selector: 'app',
templateUrl: './app.component.html'
})
export class AppComponent {}
app.component.html:
<Drawer:RadSideDrawer>
<Drawer:RadSideDrawer.mainContent>
<StackLayout>
<Label text="Test"></Label>
</StackLayout>
</Drawer:RadSideDrawer.mainContent>
<Drawer:RadSideDrawer.drawerContent>
<StackLayout class="container">
<Label text="Drawer Test"></Label>
</StackLayout>
</Drawer:RadSideDrawer.drawerContent>
</Drawer:RadSideDrawer>
No errors in console at all. App launches just fine. (no exceptions. nothing. normal log) Displays absolutely nothing. Just a white screen app. Very puzzling.
I should mention I've also tried this just for kicks. Tried several things to no avail.
component:
import {Component} from 'angular2/core';
import {registerElement} from 'nativescript-angular/element-registry';
registerElement('RadSideDrawer', () => require('nativescript-telerik-ui/sidedrawer').RadSideDrawer);
@Component({
selector: 'app',
templateUrl: './app.component.html'
})
export class AppComponent {}
app.component.html:
<RadSideDrawer>
<RadSideDrawer.mainContent>
<StackLayout>
<Label text="Test"></Label>
</StackLayout>
</RadSideDrawer.mainContent>
<RadSideDrawer.drawerContent>
<StackLayout class="container">
<Label text="Drawer Test"></Label>
</StackLayout>
</RadSideDrawer.drawerContent>
</RadSideDrawer>
Same thing. Just white app. I thought maybe it needed some height/width so I tried adding height="100%" and width="100%" on several nodes but still nothing. Stumped.
Oh and lastly the dependencies are correct using the latest:
"nativescript-telerik-ui": "^0.2.4",
I feel like I should have a play. It certainly needs the register element.
<RadSideDrawer.mainContent> ... would that need a directive? ... maybe. Take a look at:
tab views
@matt4446 good thinking... I'll try that when I get the chance.
Using directives does fix it. I have a working implementation with this:
@Directive({
selector: 'RadSideDrawer'
})
export class RadSideDrawerDirective {
public drawer: RadSideDrawer;
constructor(private element: ElementRef) {
this.drawer = element.nativeElement;
}
}
@Directive({
selector: '[mainContent]'
})
export class RadSideDrawerMainDirective {
constructor(
private owner: RadSideDrawerDirective,
private templateRef: TemplateRef,
private viewContainer: ViewContainerRef
) {
}
ngOnInit() {
const viewRef = this.viewContainer.createEmbeddedView(this.templateRef);
//Filter out text nodes, etc
const realViews = viewRef.rootNodes.filter((node) =>
node.nodeName && node.nodeName !== '#text')
if (realViews.length > 0) {
this.owner.drawer.mainContent = realViews[0];
}
}
}
@Directive({
selector: '[drawerContent]'
})
export class RadSideDrawerContentDirective {
constructor(
private owner: RadSideDrawerDirective,
private templateRef: TemplateRef,
private viewContainer: ViewContainerRef
) {
}
ngOnInit() {
const viewRef = this.viewContainer.createEmbeddedView(this.templateRef);
//Filter out text nodes, etc
const realViews = viewRef.rootNodes.filter((node) =>
node.nodeName && node.nodeName !== '#text')
if (realViews.length > 0) {
this.owner.drawer.drawerContent = realViews[0];
}
}
}
with a view like this:
<RadSideDrawer>
<RadSideDrawer.mainContent *mainContent>
<StackLayout class="container">
<Label text="Yo"></Label>
</StackLayout>
</RadSideDrawer.mainContent>
<RadSideDrawer.drawerContent *drawerContent>
<StackLayout class="container">
<Label text="Yes"></Label>
</StackLayout>
</RadSideDrawer.drawerContent>
</RadSideDrawer>
The * is very important.
I can clean this up and create a plugin? Or does the core team want to integrate this into nativescript-angular ?
I created pretty much the same thing but it didnt work. I wonder what is significantly different.
Copy and paste code time. :+1:
Yeah maybe paste it here, lemme see what the difference is.
exactly the same now (including the template) I added some logging and the significant parts are hit:
this.owner.drawer.mainContent = realViews[0];
this.owner.drawer.drawerContent = realViews[0];
I just end up with a big blank page. It is either the directives (maybe I've not assigned them to the components correctly) or it is page-router-outlet ... hmmm Maybe I'll test it without the page-router-outlet tomorrow.
seeing as the code is reached it probably has nothing to do with the directives. Sleep is needed now ;-)
Ok so the implementation is not quite right yet. Maybe @hdeshev or @vakrilov may know.
It looks like the layout containers like StackLayout are not included and ends up with just a Label.
You can see in this demo that the layout containers are not present:

This occurs with a view setup like this:
<RadSideDrawer id="drawer">
<RadSideDrawer.mainContent *mainContent>
<StackLayout class="container">
<Label text="Main Content"></Label>
</StackLayout>
</RadSideDrawer.mainContent>
<RadSideDrawer.drawerContent *drawerContent>
<StackLayout class="drawer-content">
<Label text="Drawer Content"></Label>
</StackLayout>
</RadSideDrawer.drawerContent>
</RadSideDrawer>
And using the directive setup like this:
import {ElementRef, Directive, Input, TemplateRef, ViewContainerRef} from "angular2/core";
import {TabView, TabViewItem} from "ui/tab-view";
import {RadSideDrawer} from 'nativescript-telerik-ui/sidedrawer/sidedrawer';
@Directive({
selector: 'RadSideDrawer'
})
export class RadSideDrawerDirective {
public drawer: RadSideDrawer;
constructor(private element: ElementRef) {
this.drawer = element.nativeElement;
}
}
@Directive({
selector: '[mainContent]'
})
export class RadSideDrawerMainDirective {
constructor(
private owner: RadSideDrawerDirective,
private templateRef: TemplateRef,
private viewContainer: ViewContainerRef
) {
}
ngOnInit() {
const viewRef = this.viewContainer.createEmbeddedView(this.templateRef);
//Filter out text nodes, etc
const realViews = viewRef.rootNodes.filter((node) =>
node.nodeName && node.nodeName !== '#text')
if (realViews.length > 0) {
this.owner.drawer.mainContent = realViews[0];
}
}
}
@Directive({
selector: '[drawerContent]'
})
export class RadSideDrawerContentDirective {
constructor(
private owner: RadSideDrawerDirective,
private templateRef: TemplateRef,
private viewContainer: ViewContainerRef
) {
}
ngOnInit() {
const viewRef = this.viewContainer.createEmbeddedView(this.templateRef);
//Filter out text nodes, etc
const realViews = viewRef.rootNodes.filter((node) =>
node.nodeName && node.nodeName !== '#text')
if (realViews.length > 0) {
this.owner.drawer.drawerContent = realViews[0];
}
}
}
The problems occurs somewhere with this:
const viewRef = this.viewContainer.createEmbeddedView(this.templateRef);
//Filter out text nodes, etc
const realViews = viewRef.rootNodes.filter((node) =>
node.nodeName && node.nodeName !== '#text')
if (realViews.length > 0) {
this.owner.drawer.drawerContent = realViews[0];
}
This looks very cool, but I think it would be better and more angular-friendly if we get rid of the RadSideDrawer.mainContent tags. I was thinking about possible ways to integrate components having multiple templates, and the best I came up with was something like:
<RadSideDrawer id="drawer">
<template #main>
<StackLayout class="container">
<Label text="Main Content"></Label>
</StackLayout>
</template>
<template #drawer>
<StackLayout class="drawer-content">
<Label text="Drawer Content"></Label>
</StackLayout>
</template>
</RadSideDrawer>
Of course, that would require that we create a component for the RadSideDrawer selector and manage templates there.
We are thinking of using the same approach for other components exposing multiple templates like the RadListView, for example.
@hdeshev I like your suggestion. I'm trying to find a way forward on this to implement right away and curious if there's any specific implementation details I need to make your suggestion work? Similar to directives approach above or if there's sample code you could point me to I could try? Thank you.
I'd be willing to help create a separate module (maybe nativescript-telerik-ui-ng) which would contain all the telerik-ui components for angular consumption. Would need just a couple pointers and help with the first 1 (this one) or 2 to get me started. That way it keeps these custom (3rd party lib) components out of nativescript-angular.
@NathanWalker, this will be done by the telerik-ui team. They will focus on this after their initial release at the end of March. If you want them earlier you are more than welcome to do so, but please be in sync with @ginev who is leading that team internally, so that we can later reuse your work :).
Sounds good @valentinstoychev thanks!
For anyone who stumbles on this thread from a google search make sure to check out the UI for {N} documentation at http://docs.telerik.com/devtools/nativescript-ui/Controls/Angular/SideDrawer/getting-started, as well as the samples in https://github.com/telerik/nativescript-ui-samples-angular/tree/release/sdkAngular/app/sidedrawer.
i added tns create my-app --ng & done tns plugin add nativescript-telerik-ui
this is my app.component.ts
import { Component, ViewChild, ChangeDetectorRef } from "@angular/core";
import { RadSideDrawerComponent, SideDrawerType } from "nativescript-telerik-ui/sidedrawer/angular";
@Component({
selector: "my-app",
templateUrl: "app.component.html"
})
export class AppComponent {
@ViewChild(RadSideDrawerComponent)
public drawerComponent: RadSideDrawerComponent;
private drawer: SideDrawerType;
public pages: Array<Object>;
constructor(
private _changeDetectionRef: ChangeDetectorRef) {
// List all pages here
this.pages = [
{ name: "Home" },
{ name: "About" },
{ name: "Contact" }
];
}
ngOnInit() {
this.drawer = this.drawerComponent.sideDrawer;
this._changeDetectionRef.detectChanges();
}
public openDrawer() {
console.log("drawer called...........................", JSON.stringify(this.drawer));
this.drawer.toggleDrawerState();
}
}
app.component.html
<ActionBar title="GitUsers">
<NavigationButton icon="res://icon" text="Go Back" (tap)="openDrawer()"></NavigationButton>
</ActionBar>
<RadSideDrawer #drawer>
<template drawerSide>
<StackLayout class="p bgc-white">
<ListView [items]="pages" row="1">
<template let-item="item" let-i="index">
<StackLayout>
<Label text="{{item.name}}" class="page-name" ></Label>
</StackLayout>
</template>
</ListView>
</StackLayout>
</template>
<template drawerMain>
<StackLayout class="m">
<user-list></user-list>
</StackLayout>
</template>
</RadSideDrawer>
but i am getting errors on load and clicking the side drawer icon :
JS: at /data/data/org.nativescript.myapp/files/app/tns_modules/zone.js/dist/ zone-node.js:532:18 JS: at ZoneDelegate.invokeTask (/data/data/org.nativescript.myapp/files/app/ tns_modules/zone.js/dist/zone-node.js:314:38) JS: at Object.NgZoneImpl.inner.inner.fork.onInvokeTask (/data/data/org.nativ escript.myapp/files/app/tns_modules/@angular/core/src/zone/ng_zone_impl.js:44:41 ) JS: at ZoneDelegate.invokeTask (/data/data/org.nativescript.myapp/files/app/ tns_modules/zone.js/dist/zone-node.js:313:43) JS: at Zone.runTask (/data/data/org.nativescript.myapp/files/app/tns_modules /zone.js/dist/zone-node.js:214:48) JS: at drainMicroTaskQueue (/data/data/org.nativescript.myapp/files/app/tns_ modules/zone.js/dist/zone-node.js:432:36) JS: Unhandled Promise rejection: Cannot read property 'sideDrawer' of undefined ; Zone: angular ; Task: Promise.then ; Value: TypeError: Cannot read property 's ideDrawer' of undefined JS: Error: Uncaught (in promise): TypeError: Cannot read property 'sideDrawer' o f undefined JS: EXCEPTION: TypeError: Cannot read property 'sideDrawer' of undefined JS: STACKTRACE: JS: TypeError: Cannot read property 'sideDrawer' of undefined JS: at AppComponent.ngOnInit (/data/data/org.nativescript.myapp/files/app/ap p.component.js:15:43) JS: at DebugAppView.View_AppComponent_Host0.detectChangesInternal (AppCompo nent.template.js:29:81) JS: at DebugAppView.AppView.detectChanges (/data/data/org.nativescript.myapp /files/app/tns_modules/@angular/core/src/linker/view.js:243:14) JS: at DebugAppView.detectChanges (/data/data/org.nativescript.myapp/files/a pp/tns_modules/@angular/core/src/linker/view.js:348:44) JS: at ViewRef.detectChanges (/data/data/org.nativescript.myapp/files/app/t ns_modules/@angular/core/src/linker/view_ref.js:131:65) JS: at /data/data/org.nativescript.myapp/files/app/tns_modules/@angular/core /src/application_ref.js:435:84 JS: at Array.forEach (native) JS: at ApplicationRef_.tick (/data/data/org.nativescript.myapp/files/app/tns modules/@angular/core/src/application_ref.js:435:38) JS: at ApplicationRef._loadComponent (/data/data/org.nativescript.myapp/fil es/app/tns_modules/@angular/core/src/application_ref.js:406:14) JS: at /data/data/org.nativescript.myapp/files/app/tns_modules/@angular/core /src/application_ref.js:393:19 JS: EXCEPTION: TypeError: Cannot read property 'sideDrawer' of undefined JS: ns-renderer: ERROR BOOTSTRAPPING ANGULAR JS: ns-renderer: Cannot read property 'sideDrawer' of undefined JS: JS: TypeError: Cannot read property 'sideDrawer' of undefined JS: at AppComponent.ngOnInit (/data/data/org.nativescript.myapp/files/app/ap p.component.js:15:43)
Hi @sarvagayatri it looks like the error you are experiencing is caused by an bug in the zone.js which is part of the Angular 2 library. Here is the logged issue for reference. To resolve the issue simply change the "zone.js": "^0.6.21" in the devDependencies to "zone.js": "0.6.17"
We are working with the Angular team to resolve this breaking change caused by the zone.js package, in the mean while we are upgrading any project templates that use Angular 2.0.0 to not depend on the latest versions of zone.js.
I have done this command before the tns run android npm install [email protected] Or else i got some "timers" exception
How can I implement expandable (Nested) side drawer in android and ios using RadSideDrawer ?
@srnaik What do you mean by "nested", in order to use the RadSideDrawer in {N} + Angular you can follow the short introduction article here.
@VladimirAmiorkov Thank you responding to my question, I have already referred to the article that you have posted and I could able to implement the side drawer with the help of that article. My question is that I would like to add child elements inside every side-drawer item. Please refer to the below piece of code.
**<StackLayout class="sideStackLayout">
<Label text="Primary" class="sideLabel sideLightGrayLabel">
<Label text="Primary nested Item -1" class="sideLabel sideLightGrayLabel"/>
<Label text="Primary nested Item -2" class="sideLabel sideLightGrayLabel"/>
</Label>
</StackLayout>**
Here, how can I add "Primary nested Item -1" & "Primary nested Item -2" as child elements inside "Primary" ?
P.S. The piece of code that I have written is to give you an idea of Nested feature that I am trying to achieve, I hope it was helpful.