IE 11浏览器在Angular 5中的document.selection问题

时间:2019-05-09 08:37:46

标签: javascript angular typescript internet-explorer-11 domdocument

我正在IE 11中使用angular 5测试。我需要在我的打字稿文件中使用 document.selection ,但是它的定义是未定义的。我也已经如下所示全局声明了选择,但是即使那样也没有运气。谁能帮我解决这个问题吗?

declare global{
    interface Document {
        selection?: any;
    }
}





var key = event.which || event.keyCode;
        if(key === 37 || key === 39){        
            event.stopPropagation();     
            let inputDocument = document.getElementById('numericinput');   
            let range = document.createRange();
            range.collapse(true);                       
            let iCaretPos = 0;
            if(key === 39 && this.iCaretPos < inputDocument.innerHTML.length){
                 console.log("inside if");
                 this.iCaretPos = this.iCaretPos +1;
                 range.setEnd(input.firstChild, 0);      
                 range.setStart(input.firstChild, this.iCaretPos);   
            }else if(key === 37 && iCaretPos > 0){
                 console.log("inside else");
                 this.iCaretPos = this.iCaretPos -1;
                 range.setEnd(input.firstChild, 0);      
                 range.setStart(input.firstChild, this.iCaretPos);  
            }  
            window.getSelection().removeAllRanges;      
            window.getSelection().addRange(range);  
    }
}

0 个答案:

没有答案