- In my previous post we have learnt to install Angular Material library using Bower command.
- In this demo, “We will configure the Angular Material library and explore few components”.
- The project structure created by Bower installation of Angular Material library is as follows.
- In materialDemo.html file we will be calling Angular Material library and the dependencies files.The following code shows configuring material library.
<!DOCTYPE html> <html> <head> <title>AngularJS Material Demo</title> <link rel="stylesheet" href="bower_components/angular-material/angular-material.css"> </head> <body> <script src="bower_components/angular/angular.js"></script> <script src="bower_components/angular-animate/angular-animate.js"></script> <script src="bower_components/angular-aria/angular-aria.js"></script> <script src="bower_components/angular-material/angular-material.js"></script> </body> </html>
- Now let us try a material component.To work with material component we need to create a ngApp using angular.module() method. The following code has a material button element using md-button directive.
<!DOCTYPE html> <html ng-app="myApp"> <head> <title>AngularJS Material Demo</title> <link rel="stylesheet" href="bower_components/angular-material/angular-material.css"> </head> <body ng-controller="MyController"> <md-button class="md-raised">{{buttonName}}</md-button> <md-button class="md-raised md-warn">{{buttonName}}</md-button> <md-button class="md-fab md-primary" aria-label="a Button"> {{buttonName}} </md-button> <script src="bower_components/angular/angular.js"></script> <script src="bower_components/angular-animate/angular-animate.js"></script> <script src="bower_components/angular-aria/angular-aria.js"></script> <script src="bower_components/angular-material/angular-material.js"></script> <script> var myApp = angular.module("myApp",[ "ngMaterial" ]); myApp.controller("MyController",function($scope){ $scope.buttonName= "Click Me" }); </script> </body> </html>
- The output of the previous code is as following screenshot.
- The demo code can be downloaded from the following link.