npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nativescript-ng2-cli-magic

v1.0.0

Published

Magically integrate in Angular2 web app with NativeScript.

Downloads

39

Readme

Angular 2 Style Guide MIT license Dependency Status devDependency Status

nativescript-ng2-cli-magic

Magically drop a NativeScript app into your existing Angular2 web application and reuse all your code.*

You will be adding NativeScript views, but you already knew that.

Install

npm i nativescript-ng2-cli-magic --save

Usage

  1. Use Component from nativescript-ng2-cli-magic instead of @angular/core. Why?
  2. Create NativeScript views ending with .tns.html (and/or styles ending with .tns.css) for each of your component's. How?
  3. Run your truly native mobile app with NativeScript!

Example

A sample root component, app.component.ts:

import {Component} from 'nativescript-ng2-cli-magic';

@Component({
  selector: 'app',
  templateUrl: './app.component.html'
})
export class AppComponent {}

Run for first time!

You will need to have fully completed steps 1 and 2 above.

Run your app in the iOS Simulator with:

npm run start.ios

Run your app in an Android emulator with:

npm run start.android

Welcome to the wonderfully magical world of NativeScript!

How to create NativeScript views

Based on our example above, assume app.component.html looks like this:

<main>
  <div>This is my root component</div>
</main>

You would then create a new file in app.component.tns.html like this:

<StackLayout>
  <Label text="This is my root component"></Label>
</StackLayout>

You can also use platform specific views if desired with the platformSpecific Component metadata:

import {Component} from 'nativescript-ng2-cli-magic';

@Component({
  selector: 'app',
  templateUrl: './app.component.html',
  platformSpecific: true
})
export class AppComponent {}

Then you could create separate views for iOS and Android:

  • app.component.ios.html
  • app.component.android.html

You can learn more about NativeScript view options here.

You can also install helpful view snippets for VS Code here or Atom Editor here.

You can learn more here about how this setup works and why.

Why different Component?

Component from nativescript-ng2-cli-magic is identical to Component from @angular/core, except it automatically uses NativeScript views when your app runs in a NativeScript mobile app.

The library provides a custom Decorator under the hood. Feel free to check it out here and it uses a utility here.

You can see more elaborate use cases of this magic with angular2-seed-advanced.

Special Note About AoT

Currently you cannot use custom component decorators with AoT compilation. This may change in the future but for now you can use this pattern for when you need to create AoT builds for the web:

import { Component } from '@angular/core';

// just comment this out and use Component from 'angular/core'
// import { Component } from 'nativescript-ng2-cli-magic';

@Component({
  // etc.

After doing the above, running AoT build will succeed. :)

The Component from nativescript-ng2-cli-magic does the auto templateUrl switching to use {N} views when running in the {N} app therefore you don't need it when creating AoT builds for the web. However just note that when going back to run your {N} app, you should comment back in the Component from nativescript-ng2-cli-magic. Again this temporary inconvenience may be unnecessary in the future.

Requirements

License

MIT