Input Fields
<input-field>
Materialize uses the class .input-field
to manage animating labels and input-fields. But that doesn't work properly when angular dynamically creates element
Instead of adding the class .input-field
, use the input-field directive. This way it still works when angular dynamically creates it.
You wrote: {{ inputText }}
You wrote: {{ inputTextarea }}
<div input-field> <input type="text" ng-model="dummyInputs.inputFieldInput" length="150"> <label>Input label</label></div><div input-field> <textarea ng-model="dummyInputs.textAreaInput" class="materialize-textarea"></textarea> <label>Textarea</label></div>
You can also use it as an element instead of an attribute.
<input-field> <input type="text" ng-model="dummyInputs.inputFieldInput"> <label>Input label</label></input-field> <input-field> <textarea ng-model="dummyInputs.textAreaInput" class="materialize-textarea"></textarea> <label>Textarea</label></input-field>
Input Date
<Input-date>
The below example is where there are values in all the options, but all the options are optional.
The attributes min
and max
can be any value representing a date. It should be in a format recognised by Date Constructor.
The code in the HTML
<labelfor="inputCreated">Input date</label><inputinput-datetype="text"name="created"id="inputCreated"ng-model="currentTime"container="body"format="dd/mm/yyyy"months-full="{{ month }}"months-short="{{ monthShort }}"weekdays-full="{{ weekdaysFull }}"weekdays-short="{{ weekdaysShort }}"weekdays-letter="{{ weekdaysLetter }}"disable="disable"min="{{ minDate }}"max="{{ maxDate }}"today="today"clear="clear"close="close"select-years="15"on-start="onStart()"on-render="onRender()"on-open="onOpen()"on-close="onClose()"on-set="onSet()"on-stop="onStop()"/>
And the JavaScript in the controller
varcurrentTime =newDate();$scope.currentTime =currentTime;$scope.month =['Januar','February','March','April','May','June','July','August','September','October','November','December'];$scope.monthShort =['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];$scope.weekdaysFull =['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];$scope.weekdaysLetter =['S','M','T','W','T','F','S'];$scope.disable =[false,1,7];$scope.today ='Today';$scope.clear ='Clear';$scope.close ='Close';vardays =15;$scope.minDate =(newDate($scope.currentTime.getTime()-(1000*60*60*24*days ))).toISOString();$scope.maxDate =(newDate($scope.currentTime.getTime()+(1000*60*60*24*days ))).toISOString();$scope.onStart =function(){console.log('onStart');};$scope.onRender =function(){console.log('onRender');};$scope.onOpen =function(){console.log('onOpen');};$scope.onClose =function(){console.log('onClose');};$scope.onSet =function(){console.log('onSet');};$scope.onStop =function(){console.log('onStop');};
Material select
<material-select>
Add the material-select as an attribute to the select where you want material-select. Not needed if you add the class browser-default. It doesn't support changing content within the select, add the class browser-default if you want that.
If you add the attribute watch
, then the material-select will re-initialize whenever something changes in the content within the select.
That includes if the number of list elements change.
But beware, while the implementation works, it is very heavy in computation, so tread lightly.
You selected: {{select.value1}}
<select class="" ng-model="select.value1" material-select watch> <option ng-repeat="value in select.choices">{{value}}</option></select>
Using class browser-default
You selected: {{select.value2}}
<select class="browser-default" ng-model="select.value2"> <option ng-repeat="value in select.choices">{{value}}</option></select>
Collapsible
The collapsible below is populated using ng-repeat, just to show that it is possible. You can also just manually put in the content.
In the below, the popout class is added, which makes a "Google inbox" effect. Just remove the popout class to get a normal accordion.
Since this is just a wrapper for materializes collapsible, all their customizationcan be used.
If you add the attribute watch
, then the collapsible will re-initialize whenever something changes in the content within the collapsible.
That includes if the number of list elements change.
But beware, while the implementation works, it is very heavy in computation, so tread lightly.
- {{single.title}}
{{single.content}}
The code in the HTML
<ul class="collapsible popout" data-collapsible="accordion" watch> <li ng-repeat="single in collapsibleElements"> <div class="collapsible-header"><i class="{{single.icon}}"></i>{{single.title}}</div> <div class="collapsible-body"><p>{{single.content}}</p></div> </li></ul>
And the JavaScript in the controller
$scope.collapsibleElements = [{ icon: 'mdi-image-filter-drama', title: 'First', content: 'Lorem ipsum dolor sit amet.' },{ icon: 'mdi-maps-place', title: 'Second', content: 'Lorem ipsum dolor sit amet.' },{ icon: 'mdi-social-whatshot', title: 'Third', content: 'Lorem ipsum dolor sit amet.' }];
Toasts
Materializes toast is a global function. Using this directive you can call a toast using a custom event (in the below click), and show a message determined by a variable in the scope.
The message is specified through the message attribute, and the duration is set though the duration attribute (defaults to 3000ms if not set).
<div class="row"> <div class="col s4" input-field> <input id="message" type="text" ng-model="dummyInputs.message" ng-init="dummyInputs.message = 'I\'m a message'"> <label for="message">Message</label> </div> <div class="col s2" input-field> <input id="toastDuration" type="text" ng-model="dummyInputs.duration" ng-init="dummyInputs.duration = 1000"> <label for="toastDuration">Toast duration</label> </div> <div class="input-field col s4"> <a class="waves-effect waves-light btn" message="{{dummyInputs.message}}" duration="{{dummyInputs.duration}}" toast='click'>Toast!</a> </div></div>
Tooltip
The tooltipped attribute in the below makes sure that the jQuery plugin is run.
You can set attributes on the tag, matching the names of the options in the materializeCSS's version.
<div class="col s8" ng-if="showTooltip"> <!-- data-position can be : bottom, top, left, or right --> <!-- data-delay controls delay before tooltip shows (in milliseconds)--> <a tooltipped class="btn col s4 offset-s4 l2 offset-l1" data-position="bottom" data-delay="50" data-tooltip="I am tooltip"> Bottom</a> <a tooltipped class="btn col s4 offset-s4 l2 offset-l1" data-position="top" data-delay="150" data-tooltip="I am tooltip"> Top</a> <a tooltipped class="btn col s4 offset-s4 l2 offset-l1" data-position="left" data-delay="250" data-tooltip="I am tooltip"> Left</a> <a tooltipped class="btn col s4 offset-s4 l2 offset-l1" data-position="right" data-delay="550" data-tooltip="I am tooltip"> Right</a></div>
Pushpin
The pushpin
attribute allows you to pin a particular element to the top of the page.
You can use the pushpin-top
attribute to define distance in pixels from the top of the page where the element becomes fixed. The pushpin-offset
attribute can be used to offset the distance from the top. The pushpin-bottom
attribute can be used to set the distance in pixels from the top of the page where the elements stops being fixed.
<div class="sidebar" pushpin pushpin-top="0" pushpin-offset="0" pushpin-bottom="Infinity"> <ul id="sidebarMenu" class="menu"> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> <li>Item 4</li> <li>Item 5</li> </ul></div>
Dropdown
The dropdown attribute in the below makes sure that the jQuery plugin is run.
You can set attributes on the tag, matching the names of the options in the materialize CSS's version.
<!-- Dropdown Trigger --><a class='dropdown-button btn' href='javascript:void(0);' data-activates='demoDropdown' dropdown data-hover="true"> This is a dropdown</a><!-- Dropdown Structure --><ul id='demoDropdown' class='dropdown-content'> <li><a href="javascript:void(0);">Link 1</a></li> <li><a href="javascript:void(0);">Link 2</a></li> <li><a href="javascript:void(0);">Link 3</a></li> <li><a href="javascript:void(0);">Link 4</a></li> <li><a href="javascript:void(0);">Link 5</a></li></ul>
Modals
You need a modal trigger, like the below. The trigger should have the modal directive, and the href attribute must point to the ID of the modal structure.
The modal strcture should be structured just like in materialize admin.
In the below example, you can change the header of the modal through the input field.
<!-- Modal Trigger --><div class="col"> <a class='btn' href='#demoModal' modal>Show Modal</a></div><!-- Modal Structure --><div id="demoModal" class="modal"> <div class="modal-content"> <h4>Modal header</h4> <p>A bunch of text</p> </div> <div class="modal-footer"> <a href="#!" class=" modal-action modal-close waves-effect waves-green btn-flat">Agree</a> </div></div>
Tabs
This is a very simple directive, that just calls the jQuery plugin when the element is initialized.
For the styling to work, you still need to have the class tabs
on the ul
tag
Because of the simple implementation, don't expect ng-repeat ng-model or similar to work inside the ul of the tabs (should work inside the content though).
<div class="row" ng-if="showTabs"> <div class="col s12"> <ul class="tabs" tabs> <li class="tab col s3"><a href="#test1">Test 1</a></li> <li class="tab col s3"><a class="active" href="#test2">Test 2</a></li> <li class="tab col s3"><a href="#test3">Test 3</a></li> <li class="tab col s3"><a href="#test4">Test 4</a></li> </ul> </div> <div id="test1" class="col s12">Test 1</div> <div id="test2" class="col s12">Test 2</div> <div id="test3" class="col s12">Test 3</div> <div id="test4" class="col s12">Test 4</div> </div>
Pagination
This is only the pagination buttons, it doesn't do anything to change the page. That you'll have to do in the callback
In the below, changePage is a function defined on the controller.
<pagination page="1" page-size="10" total="200" show-prev-next="true" dots="...." hide-if-empty="false" adjacent="2" scroll-top="false" pagination-action="changePage(page)" />
Parallax
Adding the parallax attribute makes sure that the jQuery plugin from Materialize admin.
It works just like the code below the image shows, and fills the entire width of the container it is put in.
<div class="parallax-container"> <div parallax><img src="images/gallary/3.jpg"></div></div>
Slider
An extremely simple directive, that just enables the slider. Just add the attribute slider
, and the slider will be initialized.
You can optionally set one of more of the attributes height
, transition
, interval
or indicators
, and the option will be passed to the slider.
i.e: <div slider height='500' transition='400'></div>
<div class="slider" slider> <ul class="slides"> <li> <img src="http://lorempixel.com/580/250/nature/1"> <!-- random image --> <div class="caption center-align"> <h3>This is our big Tagline!</h3> <h5 class="light grey-text text-lighten-3">Here's our small slogan.</h5> </div> </li> <li> <img src="http://lorempixel.com/580/250/nature/2"> <!-- random image --> <div class="caption left-align"> <h3>Left Aligned Caption</h3> <h5 class="light grey-text text-lighten-3">Here's our small slogan.</h5> </div> </li> <li> <img src="http://lorempixel.com/580/250/nature/3"> <!-- random image --> <div class="caption right-align"> <h3>Right Aligned Caption</h3> <h5 class="light grey-text text-lighten-3">Here's our small slogan.</h5> </div> </li> <li> <img src="http://lorempixel.com/580/250/nature/4"> <!-- random image --> <div class="caption center-align"> <h3>This is our big Tagline!</h3> <h5 class="light grey-text text-lighten-3">Here's our small slogan.</h5> </div> </li> </ul></div>
Media
Materialbox is intialized automatically. However, if you add images dynamically, you will have to add this initialization code.
Creating the above image with the effect is as simple as adding a class to the image tag.
<img materialboxed class="materialboxed responsive-img" width="650" src="images/sample-1.jpg">
Captions
It is very easy to add a short caption to your photo. Just add the caption as a data-caption
attribute.
Creating the above image with the effect is as simple as adding a class to the image tag.
<img materialboxed class="materialboxed" data-caption="A picture of some deer and tons of trees" width="250" src="iamges/nature_portrait_by_pw_fotografie-d63tx0n.jpg">