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-slider.html
  • View model: md-slider.js
  • File app.js
  1. 3. App developers tutorial

3.5 Slider component

Previous3.4 Button componentNext3.6 Collapsible component

Last updated 7 years ago

Unlike the previous two controls, Slider is represented (by Aurelia Materialize bridge) as an Aurelia custom element (component) - since slider is not a native HTML element.

View: md-slider.html

<template>
  <h4>Materialize slider demo</h4>
  <div class="container">
    <div class="row">
      <div class="col s8">
        <md-slider>
          <md-slide repeat.for="slide of slides" img.bind="slide.img" caption-align.bind="img.align">
            <h3>${slide.heading}</h3>
            <h5>${slide.subheading}</h5>
          </md-slide>
        </md-slider>
      </div>
    </div>
  </div>
</template>

Here is this view rendered by the application associated with this tutorial.

Image 1

The HTML code in the view is a good demonstration of Aurelia's support for declarative programming - all attributes of the slider are declared there and bound to view model shown next.

View model: md-slider.js

export class MdSliderDemo {
  slides = [
    { img: 'http://lorempixel.com/580/250/nature/1', align: 'center', heading: 'This is our big Tagline!', subheading: 'Here is our small slogan.' },
    { img: 'http://lorempixel.com/580/250/nature/2', align: 'left', heading: 'Left Aligned Caption', subheading: 'Here is our small slogan.' },
    { img: 'http://lorempixel.com/580/250/nature/3', align: 'right', heading: 'Right Aligned Caption', subheading: 'Here is our small slogan.' },
    { img: 'http://lorempixel.com/580/250/nature/4', align: 'center', heading: 'This is another big Tagline!', subheading: 'Here is our small slogan.' }
  ];
}

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' },
      { route: 'md-slider',  name: 'md-slider', moduleId: 'material/slider/md-slider', nav: true, title: 'Slider' }
    ]);

    this.router = router;
  }
}