Coder Social home page Coder Social logo

manekinekko / angular2-meteor Goto Github PK

View Code? Open in Web Editor NEW

This project forked from urigo/angular2-meteor

0.0 3.0 0.0 641 KB

Angular 2.0 and Meteor - the perfect stack

Home Page: http://www.angular-meteor.com/

License: MIT License

TypeScript 31.25% JavaScript 68.01% CSS 0.17% Shell 0.57%

angular2-meteor's Introduction

Angular2-Meteor Build Status

Angular2 + Meteor integration.

Angular2 version: beta-7.

Table of Contents

Change Log

Check out change log of the package here.

Tutorial

If you are new to Angular 2, we recommend to check out our 15-steps Angular2+Meteor tutorial.

Quick Start

Install package:

With Meteor 1.3:

    npm install angular2-meteor --save
    npm install angular2-meteor-auto-bootstrap --save

This package adds own HTML processor and TypeScript support, so you'll also need to remove the standard HTML processor:

   meteor remove blaze-html-templates

And add Angular2 compilers package:

   meteor add barbatus:ng2-compilers

For the explanation, please, read "HTML" paragraph in the above mentioned tutorial.

Notes:

  • Meteor 1.3 uses CommonJS implementation for modules loading so you do not need to use SystemJS or any other loader!

With Meteor 1.2

   meteor add angular2-meteor

Notes:

  • The compilers are part of this package.
  • Meteor 1.2 does not have modules loader, so you need to use SystemJS as modules loader (comes with this package!)

Import Angular2 into your app:

Package supports TypeScript and Babel (.jsx file extension) as languages for development with Angular2.

ES6 modules are supported via CommonsJS (starting in Meteor 1.3) module loader library.

To start, create app.ts file, import Component and View and then bootstrap the app:

    import {Component, View} from 'angular2/core';
    import {bootstrap} from 'angular2/bootstrap';

    @Component({
      selector: 'socially'
    })
    @View({
      template: "<p>Hello World!</p>"
    })
    class Socially {}

    bootstrap(Socially);

Add index.html file to the app top folder:

    <body>
       <socially></socially>
    </body>

At this point you should see app working and showing "Hello word".

If you have an HTML file in the app root folder with body or head tag (index.html in our case), the package will recognize it as your master HTML file and will skip inserting a default layout. Otherwise, it'll insert bootstrap HTML as follows:

<body>
    <app></app>
</body>

Also, if you name your main client component is app.ts, the package will import client/app it automatically.

( Note that if you use Meteor 1.2, you need to use SystemJS imports to load your main file!)

Start using Meteor in your Angular2 app:

This package comes with some modules that makes it easy to use Meteor in Angular2.

You can use Meteor collections in the same way as you would do in a regular Meteor app with Blaze, you just need to use another bootstrap method, instead of the one the comes with Angular2:

import {bootstrap} from 'angular2-meteor-auto-bootstrap';

And now you can iterate Mongo.Cursor objects with Angular 2.0 ngFor!

For example, change client/app.ts to:

    // ....

    @View({
      templateUrl: 'client/parties.html'
    })
    class Socially {
        constructor() {
          this.parties = Parties.find();
        }
    }

    // ....

Add Angular2 template file client/parties.html with a content as follows:

    <div *ngFor="#party of parties">
      <p>Name: {{party.name}}</p>
    </div>

At this moment, you are ready to create awesome apps backed by the power of Angular2 and Meteor!

To use Meteor features, make sure that your components extends MeteorComponent, and you can feature that comes from Meteor:

    import {Component, View} from 'angular2/core';
    import {bootstrap} from 'angular2-meteor-auto-bootstrap';
    import {MeteorComponent} from 'angular2-meteor';
    import {MyCollection} form '../model/my-collection.ts';

    @Component({
      selector: 'socially'
    })
    @View({
      template: "<p>Hello World!</p>"
    })
    class Socially extends MeteorComponent {
      myData : Mongo.Cursor<any>;
    
      constructor() {
         this.myData = MyCollection.find({});
         this.subscribe('my-subscription'); // Wraps Meteor.subscribe
      }
      
      doSomething() {
         this.call('server-method'); // Wraps Meteor.call
      }
    }

    bootstrap(Socially);

You can find more examples in the full tutorial!

Demos

Check out two demos for the quick how-to:

Server Side

You can use TypeScript also in the server side, so you can share you interfaces with both client and server!

Similar to the client's main module app file, Meteor checks for the existence of the main file in the server folder and, in case of success, will import it for you.

TypeScript Support

The package uses this TypeScript compilers to compile .ts-files. Please, read there how you can configure TypeScript, what options are available or how you can speed up just-in-time compilation.

TypeScript configuration file a.k.a. tsconfig.json is supported as well. Place a file with this name at the root folder and start adding any available TypeScript options you want. Read about the structure [here] (https://github.com/Microsoft/TypeScript/wiki/tsconfig.json). "files" property works only for the declaration files in the "typings" folder.

We recommend to use something like this default config file:

{
  "compilerOptions": {
    "experimentalDecorators": true,
    "module": "commonjs",
    "target": "es5",
    "isolatedModules": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "removeComments": false,
    "noImplicitAny": false,
    "sourceMap": true
  }
}

By default, all modules from node_modules are included so you do not need to handle typings when you first create an app.

Roadmap

You can check out the package's roadmap and its status under this repository's issues.

Contribution

If you know how to make integration of Angular 2 and Meteor better, you are welcome!

For the coding style guide, we use AirBnB rules with TypeScript specifics and max line width set to 100 symbols. Rules are partly enforced by the tslint.json file in the root (if you are not familiar with TSLint, read more here). Please, check that your code conforms with the rules before PR.

Clone the source to your computer

In order to work with this package locally when using Meteor 1.3 project, follow these instructions:

  1. Clone this repository to any folder. Note that if you clone into Meteor project directory - you need to put the cloned folder inside a hidden file so Meteor wont try to build it! just create a folder that starts with . under your project root, it should look like that:

    MyProject
       .local-work
          angular2-meteor
       .meteor
       client
       server
       public
    
  2. Make sure that you already have node_modules directory under your root - if not - create it:

    $ mkdir node_modules
    

    Also, make sure that you have a NPM project initialized in your directory (you should have package.json), if not, use:

    $ npm init
    
  3. Make sure that you do not have angular2-meteor already - check under node_modules - if you do, delete it.

  4. Now you have two options, you can specify the local copy in the package.json of your project, as follow:

    {
       "dependencies": {
          "angular2-meteor": "./local-work/angular2-meteor"
       }
    }

    And then make sure to run the NPM install command:

    $ npm install
    

    **Or, ** you can link the directory using NPM command like tool, as follow:

    $ npm link ./local-work/angular2-meteor
    

Building the project from sources

In order to use your local copy of Angular2-Meteor, you have two options:

  1. Import the TypeScript source code from the package, for example:

    import {MeteorComponent} from 'angular2-meteor/modules/meteor_component.ts';
    
  2. Or, you can keep the same code you have now, but you will need to build Angular2-Meteor source code each change you perform, by using the build.sh script inside the node_modules/angular2-meteor directory. The build proccess uses Webpack in order to perform the build, using ts-loader, so make sure that you have webpack package installed from NPM.

Troubleshoot

When working with local package, note that you should never have two local packages of angular2 package, you should have it only under node_modules/angular2 of the root directory. In case of weird errors regarding missing direcrtives - make sure that you do not have a copy of angular2 package under node_modules/angular2-meteor/node_modules/angular2!

angular2-meteor's People

Contributors

barbatus avatar dotansimha avatar urigo avatar dab0mb avatar ozsay avatar jcache avatar nkl3in avatar bigsan avatar sclausen avatar littlestudent avatar vamsi-innominds avatar

Watchers

James Cloos avatar Wassim Chegham avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.