I am trying mdc-components with angular4 project created using angular-cli
. So I installed moduled using npm command
npm install material-components-web
this installed
"material-components-web": "^0.22.0"
Then created a component that contains HTML markup of slider
<div #slider class="mdc-slider" tabindex="0" role="slider" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0" aria-label="Select Value">
<div class="mdc-slider__track-container">
<div class="mdc-slider__track"></div>
</div>
<div class="mdc-slider__thumb-container">
<svg class="mdc-slider__thumb" width="21" height="21">
<circle cx="10.5" cy="10.5" r="7.875"></circle>
</svg>
<div class="mdc-slider__focus-ring"></div>
</div>
</div>
On the ts side get the element using ViewChild
@ViewChild('slider') elSlider: ElementRef;
and wrapped this element using MDCSlider
class
let mdcSlider = new MDCSlider(this.elSlider.nativeElement);
and then imported sass file for the same mdc component in styles.scss
file
@import '~@material/slider/mdc-slider';
this rendered a beautiful material slider component on UI and it works fine.
To listen change event
mdcSlider.listen('MDCSlider:change', () => console.log("Value changed to ",mdcSlider.value));
and that logs the current value of slider on browser console.
But I am confused with the foundation and adapter classes of each component.
From the documentaion, I got
foundation class is to interact with the dom element and on the name of interaction I can
1) listen events
2) get/set the current value of component
and I can pass my custom adapter to the foundation class.
I have some queries on this
1) To use a component, every time, I have to use foundation class? with custom adapter implementation?
2) Any scenario or example that shows the use of foundation and adapter except for the checkbox example of angular2?
3) Is foundation class used if I have to create my own angular component?