Intro To Aurelia

Matthew Vogt

http://aurelia.io
Aurelia is a JavaScript client framework for mobile, desktop and web leveraging simple conventions and empowering creativity.

Lead by Rob Eisenberg

Developed by a dedicated team of leads and core developers with hundreds of contributions from the open source community

Highlights

All the usual things you'd expect in a modern application framework

  • Data Binding and Templating
  • Routing
  • Dependency Injection
  • HTTP Services
  • Data Validation
  • Testability

Some reasons you may want to use Aurelia and that set it apart from other frameworks

  • Open source but comercially backed
  • Convention over Configuration
  • Extensible and Integrates with others
  • Unobsrusive and easy
  • Self contained

Application building blocks

  • ES-Next or TypeScript
  • Host page
  • Module Loader/Bundler
  • Bootstrapper/main module
  • Components

Host page and loader


<!DOCTYPE html>
<html>
  <head>
    <title>Aurelia</title>
  </head>
  <body aurelia-app="src/main">
    <script src="scripts/system.js"></script>
    <script src="scripts/config-typescript.js"></script>
    <script src="scripts/aurelia-core.min.js"></script>
    <script>
      System.import('aurelia-bootstrapper');
    </script>
  </body>
</html>

						

Main module

src/main.ts


import {Aurelia} from 'aurelia-framework';

export function configure(aurelia: Aurelia) {
  aurelia.use.basicConfiguration();
  aurelia.start().then(() => aurelia.setRoot());
}						

App Component

The root container of our application.

In Aurelia, a component is a view and view-model pair. The view is for your UI markup and is written in HTML and the view-model is a TypeScript (or JavaScript) class that contains the UI logic.

by convention, they have the same file name with the .html extension for the view and .ts (or .js) extension for the view-model

src/app.ts


export class App {
	message = "Hello from Aurelia!"
}
							

src/app.html


								
							

Data Binding

Data binding to HTML element attributes





Blog
Twitter
LinkedIn
						

Data Binding

Data binding to HTML element events






    

						

Templating

Repeating

Hello, ${friend}!

${person.name}

Conditional Display

some content
some content

Routing

Basic root route configuration in app.ts

import {RouterConfiguration, Router} from 'aurelia-router';

export class App {
  configureRouter(config: RouterConfiguration, router: Router): void {
  this.router = router;
  config.title = 'Aurelia';
  config.map([
    { route: ['', 'home'],       name: 'home',       moduleId: 'home/index',    nav: true },
    { route: 'users',            name: 'users',      moduleId: 'users/index',   nav: true },
    { route: 'users/:id/detail', name: 'userDetail', moduleId: 'users/detail' }
    ]);
  }
}					

Routing

Router view in app.html

					

Routing

Activating a component

import {RouteConfig} from 'aurelia-router';

export class UserDetail {
  activate(params: any, routeConfig: RouteConfig): Promise<any> {
    //the id parameter from the route will be in params.id
	
  }
}
						

Routing

Other fun features of the Aurelia router
  • Push State
  • Nested Routers
  • Redirects and Unknown Routes
  • Navigation Pipeline
  • Layouts

Dependency Injection

Everyhthing is injectable and most things can be injected

Injecting a service into a component

import {RouteConfig} from 'aurelia-router';
import {autoinject} from 'aurelia-framework';
import {UserService} from 'services/user-service';

@autoinject
export class UserDetail {
  constructor(private userService: UserService){}

  activate(params: any, routeConfig: RouteConfig): Promise<any> {
    return this.userService.getUser(params.id).then(users => {
	  this.users = users;	
	})
  }
}
					

Creating a new Aurelia application

Two easy ways to get started: Skeleton Projects and the CLI

What else?

Any Questions?