Materialize Bridge Docs
v1
v1
  • Intro
  • 1. About this application
    • 1.1 Introduction
    • 1.2 Navigation guide
    • 1.3 Components catalog
    • 1.4 Internal Structure
    • 1.5 Installation
    • 1.6 Project status
    • 1.7 Color switcher
  • 2. Installation
    • Webpack, Aurelia-CLI (Webpack)
    • JSPM
    • Aurelia-CLI (require)
    • Fuse-box 2.x
  • 3. App developers tutorial
    • 3.1 Introduction
    • 3.2 Setup
    • 3.3 Select component
    • 3.4 Button component
    • 3.5 Slider component
    • 3.6 Collapsible component
    • 3.7 What you need to know
  • 4. App developers notes
    • 4.1 On bundling
    • 4.2 Using your own SASS with JSPM
  • 5. Contributing (bridge developers notes)
    • Cloning and running the code
    • Creating samples
  • 6. About Aurelia
    • 5.1 Key Features
  • 7. About Materialize
    • 7.1 Integrated with Aurelia
    • 7.2 Why choose Materialize
Powered by GitBook
On this page
  • View: md-button.html
  • View model: md-button.js
  • File app.js
  1. 3. App developers tutorial

3.4 Button component

Previous3.3 Select componentNext3.5 Slider component

Last updated 7 years ago

View: md-button.html

<template>
  <h4>Materialize button demo</h4>
  <div class="row">
    <div class="col s4">
      <button md-button="disabled.bind: disabled;" click.trigger="showToast()">Materialize Button</button>
    </div>
  </div>
</template>

Just like in the case of the Select control, the statement <button md-button="disabled.bind: disabled;" click.trigger="showToast()">Materialize Button</button>

results with the instantiation of the button:

Image 1

View model: md-button.js

import { inject } from 'aurelia-dependency-injection';
import { MdToastService } from 'aurelia-materialize-bridge/toast/toastService';

@inject(MdToastService)
export class MdButtonDemo {
  disabled = false;

  constructor(toast) {
    this.toast = toast;
  }

  showToast() {
    this.toast.show('You clicked me!', 2000);
  }
}

Finally, add the new component to your router-configuration:

File app.js

export class App {
  configureRouter(config, router) {
    config.title = 'Aurelia';
    config.map([
      { route: ['', 'welcome'], name: 'welcome',      moduleId: 'welcome',      nav: true, title: 'Welcome' },
      { route: 'users',         name: 'users',        moduleId: 'users',        nav: true, title: 'Github Users' },
      { route: 'child-router',  name: 'child-router', moduleId: 'child-router', nav: true, title: 'Child Router' },
      { route: 'md-select',  name: 'md-select', moduleId: 'material/select/md-select', nav: true, title: 'Select' },
      { route: 'md-button',  name: 'md-button', moduleId: 'material/button/md-button', nav: true, title: 'Button' }
    ]);

    this.router = router;
  }
}

Observe that the button control, just like the select control are HTML native elements and that Materialize Aurelia bridge adds custom attributes (md-button) that are bound to ) "matching native properties" . Note also the definition of the event triggers that are activating the code in the view model:

Materialize button