A place to illustate code usage
- make sure you have visual studio 2013 Update 4
- install typescript 1.4 for Visual Studio 2013
- run visual studio
- open solution in
code-sandbox
- run solution using chrome
Files:
-
<template> <section> <h2>child-vm code sample</h2> <h2>my name is ${myChild.name}</h2> </section> </template>
-
import m = require("views/my-child-vm"); export class ChildVM { public myChild: m.MyChildVM; constructor() { this.myChild = new m.MyChildVM("jhonny"); } }
-
export class MyChildVM { public name: string; constructor(name: string) { this.name = name; } }
Files:
-
button to add dynamic route
<h2>Dynamic Route</h2> <button click.delegate="addDynamicRoute()">Add Dynamic Route</button>
-
welcome view model handler to add dynamic route
addDynamicRoute() { this.theRouter.addRoute({ route: "dyno-view", moduleId: "views/dyno-view", nav: true, title: "dyno-view" }); this.theRouter.refreshNavigation(); }
-
<template> <section> <h2>dyno-view</h2> </section> </template>
-
export class DynoView {}
-
getActiveRouteIndex() { for (var routeIndex in this.router.navigation) { var route = this.router.navigation[routeIndex]; if (route.isActive) { return routeIndex; } } } next() { var currentIndex = this.getActiveRouteIndex(); if (currentIndex < this.router.navigation.length - 1) { currentIndex++; this.router.navigate(this.router.navigation[currentIndex].config.route, true); } } prev() { var currentIndex = this.getActiveRouteIndex(); if (currentIndex > 0) { currentIndex--; this.router.navigate(this.router.navigation[currentIndex].config.route, true); } }
-
<template> <section> <h1>wizard</h1> <div> <div class="col-md-2"> <ul class="well nav nav-pills nav-stacked"> <li repeat.for="row of router.navigation" class="${row.isActive ? 'active' : ''}"> <a href.bind="row.href">${row.title}</a> </li> </ul> </div> <button click.delegate="prev()" class="col-md-1"><</button> <div class="col-md-8"> <router-view></router-view> </div> <button click.delegate="next()" class="col-md-1">></button> </div> </section> </template>
-
<template> <section> <h2>aurelia cube</h2> <div ref="sceneDiv" style="width: 500px; height: 400px;"></div> </section> </template>
-
import THREE = require("three"); export class AureliaCube { public camera: THREE.Camera; public scene: THREE.Scene; public renderer: THREE.Renderer; public mesh: THREE.Mesh; public sceneDiv: HTMLDivElement; public attached() { this.init(); this.animate(); } public init = () => { this.scene = new THREE.Scene(); this.camera = new THREE.PerspectiveCamera(70, this.sceneDiv.offsetWidth / this.sceneDiv.offsetHeight, 1, 1000); var light = new THREE.DirectionalLight(0xffffff); light.position.set(0, 1, 1).normalize(); this.scene.add(light); var geometry = new THREE.BoxGeometry(30, 30, 30); var material = new THREE.MeshPhongMaterial({ map: THREE.ImageUtils.loadTexture('/images/aurelia-logo.png') }); this.mesh = new THREE.Mesh(geometry, material); this.mesh.position.z = -50; this.scene.add(this.mesh); this.renderer = new THREE.WebGLRenderer({ alpha: true }); this.renderer.setSize(this.sceneDiv.offsetWidth, this.sceneDiv.offsetHeight); this.sceneDiv.appendChild(this.renderer.domElement); this.render(); } public animate = () => { this.mesh.rotation.x += .01; this.mesh.rotation.y += .005; this.render(); requestAnimationFrame(this.animate); } public render = () => { this.renderer.render(this.scene, this.camera); } }