Skip to content

Instantly share code, notes, and snippets.

@pjschreifels
Last active November 12, 2016 18:54
Show Gist options
  • Save pjschreifels/026a2fe52ac4e7dd342d434f101a9ce7 to your computer and use it in GitHub Desktop.
Save pjschreifels/026a2fe52ac4e7dd342d434f101a9ce7 to your computer and use it in GitHub Desktop.
Call method from Aurelia custom element.
<template>
<require from="navbar.html"></require>
<navbar router.bind="router" sign-out.call="signOut()"></navbar>
<div class="container-fluid">
<div class="row">
<div class="col-xs-12" style="margin-top: 15px;">
<router-view></router-view>
</div>
</div>
</div>
</template>
export class App {
configureRouter(config, router) {
config.title = 'Aurelia';
config.map([
{ route: ['', 'welcome'], name: 'welcome', moduleId: 'welcome', nav: true, title: 'Welcome' },
]);
this.router = router;
}
signOut() {
alert('signout');
}
}
<!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/4.0.0-alpha.5/css/bootstrap.min.css" integrity="sha384-AysaV+vQoT3kOAXZkl02PThvDr8HYKPZhNT5h/CXfBThSRXQ6jW5DO2ekP5ViFdi" crossorigin="anonymous">
</head>
<body aurelia-app="main">
<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>
export function configure(aurelia) {
aurelia.use
.standardConfiguration()
.developmentLogging();
aurelia.start().then(() => aurelia.setRoot());
}
<template bindable="router, signOut">
<nav class="navbar navbar-dark bg-primary navbar-full">
<a class="navbar-brand" href="#" >
Test
</a>
<ul class="nav navbar-nav float-xs-right">
<li repeat.for="row of router.navigation" class="nav-item ${row.isActive ? 'active' : ''} ${row.settings.hasDropdown ? 'dropdown' : ''}">
<a class="nav-link" href.bind="row.href">${row.title}</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link" click.trigger="signOut()">Sign out</a>
</li>
</ul>
</nav>
</template>
<template>
${title}
</template>
export class Welcome {
title = 'Welcome';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment