Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

143
Vistas
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 Respuestas
Responde la pregunta

0

What are you getting on your console.log

console.log("=== native dropdown", native) ?
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda