Skip to content

Instantly share code, notes, and snippets.

@Vallabharayudu
Created August 8, 2016 10:08
Show Gist options
  • Select an option

  • Save Vallabharayudu/e72de03b490362be8c912798646ee2fd to your computer and use it in GitHub Desktop.

Select an option

Save Vallabharayudu/e72de03b490362be8c912798646ee2fd to your computer and use it in GitHub Desktop.
Sample Aurelia App routing
<template>
<compose view="nav-bar.html"></compose>
<div class="page-host">
<router-view></router-view>
</div>
<style>
.page-host{
margin-top:60px;
display:block;
}
</style>
</template>
export class App {
configureRouter(config, router){
config.title = 'Aurelia';
config.map([
{ route: ['','welcome'], name: 'welcome', moduleId: './welcome', nav: true, title:'Welcome' },
{ route: 'Bindable', name: 'Bindable', moduleId: './Bindable', nav: true, title:'Bindable Custom Element' }
]);
this.router = router;
}
}
<template>
<require from="name-tag.html"></require>
<form class="form-inline">
<div class="form-group">
<label>First name</label>
<input type="text" class="form-control" value.bind="firstName"/>
</div>
<div class="form-group">
<label>Color</label>
<input type="text" class="form-control" value.bind="color" />
</div>
</form>
<name-tag color.bind="color">${firstName}</name-tag>
<name-tag color.bind="color">${firstName}</name-tag>
</template>
export class Bindable{
constructor(){
this.firstName = 'vallabha Rayudu';
this.color='#0183d7';
}
}
<!doctype html>
<html>
<head>
<title>Aurelia</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.1/jquery.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body aurelia-app>
<h1>Loading...</h1>
<script src="https://jdanyow.github.io/rjs-bundle/node_modules/requirejs/require.js"></script>
<script src="https://jdanyow.github.io/rjs-bundle/config.js"></script>
<script src="https://jdanyow.github.io/rjs-bundle/bundles/aurelia.js"></script>
<script src="https://jdanyow.github.io/rjs-bundle/bundles/babel.js"></script>
<script>
require(['aurelia-bootstrapper']);
</script>
</body>
</html>
<template bindable="color" css="background: ${color}">
<style>
name-tag{
display:block;
}
</style>
<div class="header">
<h3>Hello</h3>
<h4>My Name is</h4>
</div>
<div class="body">
<content></content>
</div>
<div class="footer">
</div>
</template>
<template>
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle Navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">
<i class="fa fa-home"></i>
<span>${router.title}</span>
</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li repeat.for="row of router.navigation" class="${row.isActive ? 'active' : ''}">
<a href.bind="row.href">${row.title}</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="loader" if.bind="router.isNavigating">
<i class="fa fa-spinner fa-spin fa-2x"></i>
</li>
</ul>
</div>
</nav>
</template>
<template>
<h1>${message}</h1>
SirName:
<input value.one-time="Sirname" />
<br />
First Name:
<input value.bind="firstName" />
<br />
Last Name:
<input value.bind="lastName" />
<br />
full name: ${fullName}
<br />
Friend's name:
<input value.bind="potentialFriend" />
<button click.trigger="addFriend()">Add Friend</button>
<ul>
<li repeat.for="friend of friends">
${friend}
</li>
</ul>
<input type="checkbox" ref="recursive" />Repeat Details usinf checkbox custom element
<app if.bind="recursive.checked"></app>
</template>
export class welcome {
constructor(){
this.Sirname='Ikkurthi';
this.message = 'Welcome to Aurelia!';
this.firstName = 'Vallabha';
this.lastName ='Rayudu';
this.friends= [];
this.potentialFriend = '';
}
addFriend(){
if(this.potentialFriend){
this.friends.push(this.potentialFriend);
}
this.potentialFriend='';
}
get fullName() {
return `${this.Sirname} ${this.firstName} ${this.lastName}`;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment