urigo:angular-test-windows-1

v0.8.3Published 9 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

angular-meteor

The power of Meteor and the simplicity and eco-system of AngularJS

Community - Thank you so much for making the ng-conf 2015 talk happen!

ng-conf

Quick start

  1. Install Meteor $ curl https://install.meteor.com | /bin/sh
  2. Create a new meteor app using $ meteor create myapp or navigate to the root of your existing app
  3. Install urigo:angular $ meteor add urigo:angular

Resources

Contributing

We would love contributions in:

  1. Code
  2. Tutorial - our goal with the tutorial is to add as many common tasks as possible. If you want to create and add your own chapter we would be happy to help you writing and adding it.
  3. Roadmap - you can add a card about what you want to see in the library or in the tutorial.
  4. I (Urigo) live around the world with one small bag, so another way of contributing can be by offering me a place to sleep somewhere interesting around the world that I have to see :)

Contributor Developer Setup

Create your Meteor Project

meteor create myProject
cd myProject

Create a packages directory and clone from your forked repo

mkdir packages
cd packages
git clone https://github.com/[your_username]/angular-meteor.git my-package

Add your local package

cd ..
meteor add my-package

Now you can start using your own copy of the angular-meteor project from myProject.

Usage

Table of Contents

App initialization

If you have a module called myModule, you can initialize your app like you would normally and by specifying angular-meteor as a dependency:

1var myModule = angular.module('myModule', ['angular-meteor']);

You don't need to bootstrap the application manually, simply specifying the ng-app attribute on a container element will do.

More in step 0 in the tutorial

Data binding

From angular-meteor version 0.6 you can use Angular's default template delimiters and there is no need to change them.

However, you need to write your Angular template markup in .ng.html files, since Meteor won't look at those files as Spacebars templates. Tying HTML and .ng.html files together isn't very difficult, we can simply use Angular's ng-include.

Please note that the names of the templates to Angular will be their URL as Meteor sees it when minifying the .ng.html files. Hence every template URL is relative to the root of the Meteor project, and contains no leading forward slash. This is important to note when working with ng-include to include templates.

client/index.html:

1<head>
2    <title>Angular and Meteor</title>
3</head>
4
5<body>
6    <div ng-app="myModule">
7        <ng-include src="'client/views/user.ng.html'"></ng-include>
8        <ng-include src="'client/views/settings.ng.html'"></ng-include>
9    </div>
10</body>

client/views/user.ng.html:

1<div>
2    <label>Name:</label>
3    <input type="text" ng-model="yourName" placeholder="Enter a name here">
4
5    <h1>Hello {{yourName}}!</h1>
6</div>

More in step 0 of the tutorial

Using Meteor Collections

angular-meteor provides 3-way data binding (view-client-server) by tying a Meteor collection to an Angular model. The API to accomplish this is $meteor.collection.

1$scope.todos = $meteor.collection(Todos);

More in step 3 of the tutorial

Subscribe

$meteor.subscribe is a wrapper for Meteor.subscribe that returns a promise.

Here's an example of how to tie a Meteor collection to a clean Angular model in the form of an array:

1$meteor.subscribe('Todos').then(function () {
2    $scope.todos = $meteor.collection(Todos);
3});

Adding controllers, directives, filters and services

When adding controllers and the likes, remember to use Dependency Injection. This is common Angular practice and helps you avoid problems when minifying and obfuscating code.

1app.controller('TodoCtrl', ['$scope', '$meteor',
2  function($scope, $meteor) {
3
4    $scope.todos = $meteor.collection(Todos);
5
6    $scope.addTodo = function() {
7      $scope.todos.push({text:$scope.todoText, done:false});
8      $scope.todoText = '';
9    };
10
11    $scope.saveTodo = function(){
12      $scope.todos.save($scope.newTodo);
13    };
14  }
15]);

Routing

Use to official AngularUI ui-router Meteor package - angularui:angular-ui-router

More on how to actually use angular-ui-router in step 5 of the tutorial

<meteor-include>

You can include Meteor's native templates with the meteor-include directive.

1<template name="todoList">
2    A couple of todos
3</template>
4
5<meteor-include src='todoList'></meteor-include>

Passing arguments to meteor-include

To pass parameters to a meteor-include directive, create a Blaze template that includes the template you want to include with parameters and include that template with meteor-include:

 <template name="quickFormWithParameters">
   {{> quickForm collection="Books" id="insertBookForm" type="insert"}}
 </template>
 
 <meteor-include src="quickFormWithParameters">
 

Caveat regarding <meteor-include>

Since 0.6 release, angular-meteor relies more heavily on Angular's default templating system and it is now usually recommended that you use ng-include over meteor-include. This is because you can't use Angular's template delimiters directly within Meteor templates and you would still need to use an ng-include directive to include any Angular template markup in your Meteor templates.

User Authentication

angular-meteor provides complete for the Meteor accounts system. more details here - Documentation.

More in step 8 of the tutorial

Meteor methods with promises

$meteor.call calls a Meteor method and returns a promise.

1$meteor.call('addUser', username).then(function (data) {
2    console.log('User added', data);
3});

Bind Meteor session

$meteor.session binds a scope variable to a Meteor Session variable.

1$meteor.session('counter').bind($scope, 'counter');

Additional packages

The following is a non-exhaustive list of Meteor packages common Angular libraries:

Feel free to make more Angular packages and add them to that list as well.

Acknowledgement

This project started as ngMeteor, a pre-0.9 meteorite package. Since then a lot has changed but that was the main base.

Also, a lot of features were inspired by @superchris's angular-meteor fork of ngMeteor