angular2-materialize-v1
Angular 2 support for Materialize CSS v1.0+ framework.
This project has 0 dependencies and requires no dependencies to be installed on your production server. Forget the need to install hammerjs or jquery. It is made with vanilla TypeScript and vanilla Angular.
We also added all TypeScript interfaces for materialize options. You can now see what options are available in most IDE's for each function.
Project Setup
Feel free to take a look at the example-project to help you get started.
First, install materialize-css at the latest version if you haven't already
npm install materialize-css@next
Then install angular2-materialize-v1 to get this package
npm install angular2-materialize-v1
Go to angular.json
and find projects->PROJECT_NAME->architect->build->options and add
"node_modules/materialize-css/dist/css/materialize.min.css"
to the styles array (first in list)"node_modules/materialize-css/dist/js/materialize.min.js"
to the scripts array
It should look like the following
If you want material icons, go into the index.html
and add <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
to the head like so.
<!-- ect -->
After the dependencies are installed, you will be able to use angular2-materialize-v1!
Using angular2-materialize-v1
To begin, import Angular2MaterializeV1Service
in any angular component
you wish to use it in.
;
Step 2, inject it into your component using the constructor
constructorprivate angular2MaterializeService: Angular2MaterializeV1Service ...
Step 3, have your component implement AfterViewInit
Final step, implement ngAfterViewInit. ngAfterViewInit is where you will call any Angular2MaterializeV1Service
functions. It is necessary that you use this hook instead of constructor
or ngOnInit
because the view must load
before trying to make calls to it.
public ngAfterViewInit: void
The final class should look like this.
;;
Depending on what you pass into the init functions, you can cast the return value to get the class.
// passing in an id will return a single instance ; // passing in a class will return an array ;
TypeScript (JavaScript section for materializecss.com)
For a full list of examples in the github code, check out the example project code here: https://github.com/tuffant21/angular2-materialize-v1/tree/master/example-project/src/app/components
AutoInit
Auto Init allows you to initialize all of the Materialize Components with a single function call that are currently rendered in the angular view. It is important to note that you cannot pass in options using this method.
constructorprivate angular2MaterializeService: Angular2MaterializeV1Service public ngAfterViewInit: void
Autocomplete
// initialize a single autocomplete with an idthis.angular2MaterializeService.initAutocomplete'#autocomplete-id'; // initialize all carousels with class .autocompletethis.angular2MaterializeService.initAutocomplete'.autocomplete'; // initialization with optionsthis.angular2MaterializeService.initAutocomplete'.autocomplete', ;
Carousel
// initialize a single carousel with an idthis.angular2MaterializeService.initCarousel'#carousel-id'; // initialize all carousels with class .carouselthis.angular2MaterializeService.initCarousel'.carousel'; // initialization with optionsthis.angular2MaterializeService.initCarousel'.carousel', ;
CharacterCount
// initialize a single CharacterCount with an idthis.angular2MaterializeService.initCharacterCount'#characterCount-id';
Chips
// initialize a single Chips with an idthis.angular2MaterializeService.initChips'#chips-id'; // initialize all Chips with class .Chipsthis.angular2MaterializeService.initChips'.chips'; // initialization with optionsthis.angular2MaterializeService.initChips'.chips', ;
Collapsible
// initialize a single Collapsible with an idthis.angular2MaterializeService.initCollapsible'#collapsible-id'; // initialize all Collapsibles with class .Collapsiblethis.angular2MaterializeService.initCollapsible'.collapsible'; // initialization with optionsthis.angular2MaterializeService.initCollapsible'.collapsible', ;
Datepicker
// initialize a single Datepicker with an idthis.angular2MaterializeService.initDatepicker'#datepicker-id'; // initialize all Datepickers with class .Datepickerthis.angular2MaterializeService.initDatepicker'.datepicker'; // initialization with optionsthis.angular2MaterializeService.initDatepicker'.datepicker', ;
Dropdown
// initialize a single Dropdown with an idthis.angular2MaterializeService.initDropdown'#dropdown-trigger-id'; // initialize all Dropdowns with class .Dropdownthis.angular2MaterializeService.initDropdown'.dropdown-trigger'; // initialization with optionsthis.angular2MaterializeService.initDropdown'.dropdown-trigger', ;
FloatingActionButton
// initialize a single FloatingActionButton with an idthis.angular2MaterializeService.initFloatingActionButton'#floatingActionButton-id'; // initialize all FloatingActionButtons with class .FloatingActionButtonthis.angular2MaterializeService.initFloatingActionButton'.fixed-action-btn'; // initialization with optionsthis.angular2MaterializeService.initFloatingActionButton'.fixed-action-btn', ;
Materialbox
// initialize a single Materialbox with an idthis.angular2MaterializeService.initMaterialbox'#materialbox-id'; // initialize all Materialboxs with class .Materialboxthis.angular2MaterializeService.initMaterialbox'.materialboxed'; // initialization with optionsthis.angular2MaterializeService.initMaterialbox'.materialboxed', ;
Modal
// initialize a single Modal with an idthis.angular2MaterializeService.initModal'#modal-id'; // initialize all Modals with class .Modalthis.angular2MaterializeService.initModal'.modal'; // initialization with optionsthis.angular2MaterializeService.initModal'.modal', ;
Parallax
// initialize a single Parallax with an idthis.angular2MaterializeService.initParallax'#parallax-id'; // initialize all Parallaxs with class .Parallaxthis.angular2MaterializeService.initParallax'.parallax'; // initialization with optionsthis.angular2MaterializeService.initParallax'.parallax', ;
Pushpin
// initialize a single Pushpin with an idthis.angular2MaterializeService.initPushpin'#pushpin-id'; // initialize all Pushpins with class .Pushpinthis.angular2MaterializeService.initPushpin'.pushpin'; // initialization with optionsthis.angular2MaterializeService.initPushpin'.pushpin', ;
ScrollSpy
// initialize a single ScrollSpy with an idthis.angular2MaterializeService.initScrollSpy'#ScrollSpy-id'; // initialize all ScrollSpys with class .ScrollSpythis.angular2MaterializeService.initScrollSpy'.scrollspy'; // initialization with optionsthis.angular2MaterializeService.initScrollSpy'.scrollspy', ;
Select
// initialize a single Select with an idthis.angular2MaterializeService.initSelect'#Select-id'; // initialize all elements of type selectthis.angular2MaterializeService.initSelect'select'; // initialize all Selects with class .selectthis.angular2MaterializeService.initSelect'.select'; // initialization with optionsthis.angular2MaterializeService.initSelect'.select', ;
Sidenav
// initialize a single Sidenav with an idthis.angular2MaterializeService.initSidenav'#Sidenav-id'; // initialize all Sidenavs with class .Sidenavthis.angular2MaterializeService.initSidenav'.sidenav'; // initialization with optionsthis.angular2MaterializeService.initSidenav'.sidenav', ;
Slider
// initialize a single slider with an idthis.angular2MaterializeService.initSlider'#slider-id'; // initialize all sliders with class .sliderthis.angular2MaterializeService.initSlider'.slider'; // initialization with optionsthis.angular2MaterializeService.initSlider'.slider', ;
Tabs
// initialize a single Tabs with an idthis.angular2MaterializeService.initTabs'#Tabs-id'; // initialize all Tabss with class .Tabsthis.angular2MaterializeService.initTabs'.tabs'; // initialization with optionsthis.angular2MaterializeService.initTabs'.tabs', ;
TapTarget
// initialize a single TapTarget with an idthis.angular2MaterializeService.initTapTarget'#TapTarget-id'; // initialize all TapTargets with class .tap-targetthis.angular2MaterializeService.initTapTarget'.tap-target'; // initialization with optionsthis.angular2MaterializeService.initTapTarget'.tap-target', ;
Timepicker
// initialize a single Timepicker with an idthis.angular2MaterializeService.initTimepicker'#Timepicker-id'; // initialize all Timepickers with class .timepickerthis.angular2MaterializeService.initTimepicker'.timepicker'; // initialization with optionsthis.angular2MaterializeService.initTimepicker'.timepicker', ;
Tooltip
// initialize a single Tooltip with an idthis.angular2MaterializeService.initTooltip'#Tooltip-id'; // initialize all Tooltips with class .Tooltipthis.angular2MaterializeService.initTooltip'.tooltipped'; // initialization with optionsthis.angular2MaterializeService.initTooltip'.tooltipped', ;
toast
// initialization with optionsthis.angular2MaterializeService.toast; // dismiss toaststhis.angular2MaterializeService.dismissAllToasts;
textareaAutoResize
this.angular2MaterializeService.textareaAutoResize;
updateTextFields
this.angular2MaterializeService.updateTextFields;