I have String text and I want to show how many words I hide based on screen width.
This is what I have so far:
app.filter('words', function () {
return function (input, words) {
if (isNaN(words)) return input;
if (words <= 0) return '';
if (input) {
var inputWords = input.split(/\s+/);
if (inputWords.length > words) {
var theLength = inputWords.length - words;
input = inputWords.slice(0, words).join(' ') + ' + ' + theLength;
}
}
return input;
};
});
This filter works for fixed count of words. If words = 5 means we can see only 5 words and other will be hidden.
But I looking for way to make words number dynamic based on element width. For example for <div> width 200 px I show 12 words, (maybe more maybe less), for 40px - or zero words (if word too long) or one word,
I think I need mix with some directive that should take element width and calculate words number.
This is a Demo:

Thank you very much for help,