opendave opendave - 27 days ago 7
AngularJS Question

Gradients with Angular Material md-colors directive

I'm wondering if there is any way to do gradients using the Angular Material md-colors directive?

https://material.angularjs.org/1.1.1/api/directive/mdColors

Thanks

Answer

It doesn't seem possible with the md-colors directive but you can do it programatically - CodePen

Markup

<div ng-controller="AppCtrl as ctrl" ng-cloak="" ng-app="MyApp" layout-fill layout-padding layout="column">
  <div style="background: linear-gradient({{ctrl.color1}}, {{ctrl.color2}})" flex></div>
</div>

JS

angular.module('MyApp',['ngMaterial'])

.controller('AppCtrl', function($mdColors) {
  this.color1 = $mdColors.getThemeColor('primary-600');
  this.color2 = $mdColors.getThemeColor('primary-100');
});

Note that this won't work with IE. From the docs:

enter image description here

Comments