Answer the question
In order to leave comments, you need to log in
How to avoid errors occurring before all scripts are connected?
Good day.
To filter content by tags that are set by the user, I use the ngTagsInput module, filtering occurs using such code, which is located in app.js
app.filter('filterByTags', function () {
return function (items, tags) {
var filtered = [];
(items || []).forEach(function (item) {
var matches = tags.some(function (tag) {
return (item.text.indexOf(tag.text) > -1) ||
(item.text.indexOf(tag.text) > -1);
});
if (matches) {
filtered.push(item);
}
});
if (tags === undefined || tags.length === 0) {
return items;
} else {
return filtered;
}
};
});
TypeError: Cannot read property 'length' of undefined
Answer the question
In order to leave comments, you need to log in
I see 3 options, but I don’t guarantee that at least 1 of them will work as it should))) but they will still push you to the right thoughts ...
1) Place the code somewhere in the footer
2) Set the if "condition when fully loaded page"
3) Register ignoring errors (probably the worst option)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question