My question is different to Get mdslider value in angular 2? in that I needed to pass the value of the slider to the component, not just use a local variable; but also in respect of Angular Material having changed so that the slider now requires an $event object to be passed to the component function.
I have an Angular Material slider component in Angular 4:
HTML
<mat-slider min="430" max="500" step="10" value="450" (input)="pitch($event)"></mat-slider>
TS
import { Component, OnInit } from '@angular/core';
import { Inject, Injectable } from '@angular/core';
import { MatSlider } from '@angular/material';
import { AudioContext } from 'angular-audio-context';
@Component({
selector: 'pitch-slider',
templateUrl: './pitch-slider.component.html',
styleUrls: ['./pitch-slider.component.css']
})
export class PitchSliderComponent implements OnInit {
constructor(private _audioContext: AudioContext) { }
ngOnInit() {
}
}
I am quite new to Angular and I'm having trouble getting the current value of the slider. It doesn't seem to work with $event object?
With (input) event when you click outside of mat-slider, it still fired this event.
I changed it to (change) event.
This is my way to display value of mat-slider, I share for whom concern.
TS file
HTML file
Demo https://stackblitz.com/edit/angular-display-mat-slider-value?file=app/slider-overview-example.html
I was confused about the $event object - I needed to ref it with just event in the component.ts:
HTML
TS