I'm trying to create a filter that would transform a string in real time when a browser is being resized and hits a media query break-point.
I just want to :
- display
"string.short"when min-width <= 200px - display
"string.long"when min-width > 200px - make it generic and reusable (don't want to put code in a controller)
- can't use a directive because, I will be filling things like title/value/alt attributes
So far, it's working at load time (without resizing), but I want to add the browser resize detection to adapt the label if the user resize its browser.
HTML :
<input value="{{ 'string' | responsivize}}" />
Filter :
angular.module('filters.responsivize', [])
.filter('responsivize', [function() {
return function(key) {
var showShort = function() {
return Modernizr && !Modernizr.mq('only all and (min-width: 768px)');
};
//TODO: add any way to wath this in real time ?
//$rootScope.$watch(showShort, function () {});
//jQuery(window).resize(function() {});
return key.concat(showShort() ? '.short' : '.long');
};
}]);
(partially) Working jsfiddle http://jsfiddle.net/2Q8eL/2/