Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

135
Visualizações
Cannot read properties of undefined (reading 'substr')

Hi I am trying to get a substring from a string based on some calculations but getting this error in browser console:

        
        TypeError: Cannot read properties of undefined (reading 'substring')
           at MessageVariantCardInputComponent.onInput 
           at MessageVariantCardInputComponent_input_HostBindingHandler
        

when using below code sample to get the substring value of "value"

Code:

        
      
    @HostListener('input') onInput() {  
    this.triggerFound = false;
    this.triggerName = '';
    const native = this.element.nativeElement;
    console.log("=== native dropdown", native)
    const value = native.value;
    const currentPos = native.selectionStart - 1;
    
    for (const key of Object.keys(this.triggers)) {
        const trigger = this.triggers[key];
        const triggerLen = trigger.length;
        const extractedString = value.substr(currentPos - triggerLen + 1, triggerLen);
        const found = extractedString === trigger;
        const isFirstTrigger = key === 'firstElement';
    
        if ((isFirstTrigger && found && currentPos === 0) || // allow first element trigger only when current pos is 0
            (!isFirstTrigger && found)
          ) {
                this.triggerFound = true;
                this.triggerName = trigger;
                break;
            }
        }
    }

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

What are you getting on your console.log

console.log("=== native dropdown", native) ?
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda