Search code examples
angularbootstrap-4ng-bootstrapng-bootstrap-modal

Why the dynamically generated inputs return NaN?


I've created a modal that returns all number input elements to generate in HTML, but when i insert a number inside, if i write the array (example: {{ ng_model_m[i] }}) inside ngFor, it will return the value, but if i write the ngModel (example: sm.m_prova), it will return NaN.

Project: https://stackblitz.com/edit/angular-jbzmnq?file=src%2Fapp%2Fschemamasse-comp.component.ts

UPDATE: When i generate ngModel, i generate also name attribute and i've seen in "Inspect Element" that there isn't name attribute inside the element input, but there is ng-reflect-name and if a print on console by event.target.name, it doesn't print nothing.


Solution

  • two thinks about ngb-model, when you receive the promise you need use then((resultIfClose)=>{...},(resultIfDismmis)=>{...}

    If you don't want to make nothing when use activeModal.dismiss include a empty function

    modalRef.result
        .then((res) =>{
         ...
             },
         ()=>{} //<--this
        );
    

    Second, "res" is the value you pass in close function, in your stackblitz you pass a string 'prova' and want to iterate as it was an array