Element
type is general for all html element (not only inputs) and yes - there are no value
property in that type. In order to enjoy using TypeScript, we need to understand that sometimes casting an object to a specific type IS A MUST. in our use-case the type is HTMLInputElement
which represens inputs (which got value
property). So:
this.filterControl.forEach(function(item: HtmlInputElement, index: number) {
if (!item) return; // maybe there are other elements which are not inputs like div, span, etc.
computedFilters += item.getAttribute('data-filter') + '(' + item.value +
item.getAttribute('data-scale') + ')';
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…