Skip to content

Instantly share code, notes, and snippets.

@vakrilov
Last active November 12, 2022 12:47
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vakrilov/522dbd30085142c515a5359658f06e54 to your computer and use it in GitHub Desktop.
Save vakrilov/522dbd30085142c515a5359658f06e54 to your computer and use it in GitHub Desktop.
import {Directive, ViewContainerRef, TemplateRef, Inject} from '@angular/core';
import {Device, platformNames} from "platform";
import {DEVICE} from "nativescript-angular/platform-providers";
@Directive({ selector: "[ifAndroid]" })
export class IfAndroidDirective {
constructor( @Inject(DEVICE) device: Device, container: ViewContainerRef, templateRef: TemplateRef<Object>) {
if (device.os === platformNames.android) {
container.createEmbeddedView(templateRef);
}
}
}
@Directive({ selector: "[ifIos]" })
export class IfIosDirective {
constructor( @Inject(DEVICE) device: Device, container: ViewContainerRef, templateRef: TemplateRef<Object>) {
if (device.os === platformNames.ios) {
container.createEmbeddedView(templateRef);
}
}
}
<ActionBar title="test">
<ActionItem text="android" *ifAndroid></ActionItem>
<ActionItem text="ios" *ifIos></ActionItem>
</ActionBar>
@relez
Copy link

relez commented Nov 4, 2016

Hey there, I am trying to implement *ifAndroid and *ifIos directives into my dashboard.component.ts component but it is not working, I added the ts code inside my dashboard.component.ts and using *ifIos/*ifAndroid in my html file but no luck. Do I have to create different files for the ts code and then import into my dashboard.component.ts component?

Thanks!

@MContagious
Copy link

in ngModule you have to add these as declarations

@MContagious
Copy link

There is a problem with this approach. It is not rendering icons.

<ActionBar title="vCard">
   <NavigationButton icon="res://ic_menu" *ifAndroid text="Menu"></NavigationButton>
   <ActionItem icon="res://ic_menu" ios.position="left" *ifIso text="Menu"></ActionItem>
</ActionBar>

For above code it is not rendering the icons.

@chrillewoodz
Copy link

Still doesn't render any icons however.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment