material
material copied to clipboard
class-* similar to hide-* and show-*
Similar to hide-* and show-*, class-* attributes enable to apply CSS class name for a specific range of devices sm, gt-sm, md, gt-md, lg and gt-lg.
You can use it the same way you are already using hide-* and show-*. Here is an example:
<img class-sm="size-sm" class-gt-sm="size"/>
.size-sm { width: 100px; }
.size { width: 200px; }
Here is an example of implementation:
(function () {
"use strict";
angular.module("YourAppName")
// directive class-sm
.directive("classSm", [
"$mdMedia",
function($mdMedia) {
if ($mdMedia("sm")) {
return {
restrict: "A",
link: function(scope, elem, attrs) {
elem.addClass(attrs.classSm);
}
};
}
}
])
// directive class-gt-sm
.directive("classGtSm", [
"$mdMedia",
function($mdMedia) {
if ($mdMedia("gt-sm")) {
return {
restrict: "A",
link: function(scope, elem, attrs) {
elem.addClass(attrs.classGtSm);
}
};
}
}
])
// directive class-md
.directive("classMm", [
"$mdMedia",
function($mdMedia) {
if ($mdMedia("md")) {
return {
restrict: "A",
link: function(scope, elem, attrs) {
elem.addClass(attrs.classMd);
}
};
}
}
])
// directive class-gt-md
.directive("classGtMd", [
"$mdMedia",
function($mdMedia) {
if ($mdMedia("gt-md")) {
return {
restrict: "A",
link: function(scope, elem, attrs) {
elem.addClass(attrs.classGtMd);
}
};
}
}
])
// directive class-lg
.directive("classLg", [
"$mdMedia",
function($mdMedia) {
if ($mdMedia("lg")) {
return {
restrict: "A",
link: function(scope, elem, attrs) {
elem.addClass(attrs.classLg);
}
};
}
}
])
// directive class-gt-lg
.directive("classGtLg", [
"$mdMedia",
function($mdMedia) {
if ($mdMedia("gt-lg")) {
return {
restrict: "A",
link: function(scope, elem, attrs) {
elem.addClass(attrs.classGtLg);
}
};
}
}
])
;
}());
I think it could be useful to add it as a builtin feature.
Interesting feature but not in scope and focus for ngMaterial.
+1 I would also like to see this.
@noilly That issue is already implemented, see @ThomasBurleson's solution in #3815.
- #7121 was an attribute wrapper for
$mdMedia
@DevVersion cool, thank you! :)