if ( this.activeSuggestion = this.getFirstMatchingSuggestion( newValue ) ) { // NOTE: We are using only the ending portion of the suggestion, // rather than applying the suggestion in its entirety, so that we // don't override the key-casing of the existing user-provided text. var suggestionSuffix = this.activeSuggestion.slice( selectionStart ); // NOTE: We are changing the value of the INPUT ELEMENT; however, we // are NOT CHANGING the "source of truth" value that we have stored // in the class. this.elementRef.nativeElement.value = ( newValue + suggestionSuffix ); // After we update the Input element, we want to select the portion // of the text that makes up the suggestion. This way, as the user // continues to type, the selected text will naturally be removed. this.elementRef.nativeElement.selectionStart = selectionStart; this.elementRef.nativeElement.selectionEnd = this.activeSuggestion.length; }