Unable to get the reference of the elements inside modal using @viewchild











up vote
0
down vote

favorite












I am working on an Angular-6 Project. I have created a form inside ngxbootstrap modal which is working fine. That form has various input elements I want to access few of these elements but the issue is whenever I try to access those elements using @viewchild, the result is undefined which is basically due to the fact that those elements don't exist on DOM.So, Is there any way I can access them below is my code...



@Component({
selector: 'app-roles',
templateUrl: './roles.component.html',
styleUrls: ['./roles.component.scss'],
providers:[NgbActiveModal],
})
export class RolesComponent implements OnInit,AfterViewInit {
@ViewChild('dataTable') table:ElementRef;
@ViewChild('rolename') rolename:ElementRef; //Here it shows undefined
dataTable:any;
roleref:any;
error_array=new Array();
all_roles=new Array();
added:boolean;
closeResult: string;
modalRef: NgbModalRef;
is_shown:boolean;


profileForm=new FormGroup({
rolename:new FormControl('',[Validators.required,Validators.minLength(4)])
});
constructor(private roleservice:RolesService,private fb:FormBuilder,private
modalService: NgbModal,public activeModal: NgbActiveModal)
{
}

ngOnInit() {
this.dataTable=$(this.table.nativeElement);
this.dataTable.dataTable();

}

ngAfterViewInit() {
}

open(content,form:NgForm) {
this.is_shown=true;
this.modalRef = this.modalService.open(content,{
size: "lg",
centered: false,
backdrop: 'static'});
this.modalRef.result.then((result) => {
this.closeResult = `Closed with: ${result}`;
}, (reason) => {
this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
});
}

private getDismissReason(reason: any): string {
this.is_shown=false;
this.profileForm.reset();
if (reason === ModalDismissReasons.ESC) {
return 'by pressing ESC';
} else if (reason === ModalDismissReasons.BACKDROP_CLICK) {
return 'by clicking on a backdrop';
} else {
return `with: ${reason}`;
}
}
}


Below Given Is HTML code



  <ng-template #content let-d="dismiss">
<form class="form" [formGroup]="profileForm" (ngSubmit)="onSubmit()" autocomplete="off" >
<div class="modal-header">
<h4 class="modal-title">Add New Role</h4>
<button type="button" #clsbtn class="close" aria-label="Close" (click)="d('Cross click')">
<span aria-hidden="true">&times;</span>
</button>
</div>

<div class="modal-body" *ngIf="is_shown==true">
<div class="modal-body">
<div class="col-md-5">
<div class="card-content">
<div class="input-group">
<span class="input-group-addon">
<i class="material-icons">face</i>
</span>
<div class="form-group"><input type="text" #rolename formControlName="rolename" class="form-control" placeholder="RoleName..." required/><span class="material-input"></span></div>
<div *ngIf="profileForm.get('rolename').invalid && profileForm.get('rolename').touched" class="alert alert-danger">
<div *ngIf="profileForm.get('rolename').errors.required">
RoleName is required.
</div>
<div *ngIf="profileForm.get('rolename').errors.minlength">
RoleName must be at least 4 characters long.
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<!--<button type="button" class="btn btn-light" (click)="d('Close click')">Close</button>-->
<button class="btn btn-danger btn-round" style="position:relative;right:60px" [disabled]="profileForm.invalid">
<i class="material-icons">check</i> Add
</button>
</div>
</form>
</ng-template>









share|improve this question
























  • no i havent will it work?
    – Talha Sarwar
    Nov 22 at 13:50










  • @PierreDuc i tried it and i got Cannot read property 'nativeElement' of undefined
    – Talha Sarwar
    Nov 22 at 13:52






  • 1




    did you try accessing it inside ngAfterViewInit() Life Cycle method.
    – Suresh Kumar Ariya
    Nov 22 at 13:54










  • yes indeed i have but the same issue
    – Talha Sarwar
    Nov 22 at 13:57










  • Where is the dataTable in your html?
    – Yousef khan
    Nov 22 at 14:13















up vote
0
down vote

favorite












I am working on an Angular-6 Project. I have created a form inside ngxbootstrap modal which is working fine. That form has various input elements I want to access few of these elements but the issue is whenever I try to access those elements using @viewchild, the result is undefined which is basically due to the fact that those elements don't exist on DOM.So, Is there any way I can access them below is my code...



@Component({
selector: 'app-roles',
templateUrl: './roles.component.html',
styleUrls: ['./roles.component.scss'],
providers:[NgbActiveModal],
})
export class RolesComponent implements OnInit,AfterViewInit {
@ViewChild('dataTable') table:ElementRef;
@ViewChild('rolename') rolename:ElementRef; //Here it shows undefined
dataTable:any;
roleref:any;
error_array=new Array();
all_roles=new Array();
added:boolean;
closeResult: string;
modalRef: NgbModalRef;
is_shown:boolean;


profileForm=new FormGroup({
rolename:new FormControl('',[Validators.required,Validators.minLength(4)])
});
constructor(private roleservice:RolesService,private fb:FormBuilder,private
modalService: NgbModal,public activeModal: NgbActiveModal)
{
}

ngOnInit() {
this.dataTable=$(this.table.nativeElement);
this.dataTable.dataTable();

}

ngAfterViewInit() {
}

open(content,form:NgForm) {
this.is_shown=true;
this.modalRef = this.modalService.open(content,{
size: "lg",
centered: false,
backdrop: 'static'});
this.modalRef.result.then((result) => {
this.closeResult = `Closed with: ${result}`;
}, (reason) => {
this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
});
}

private getDismissReason(reason: any): string {
this.is_shown=false;
this.profileForm.reset();
if (reason === ModalDismissReasons.ESC) {
return 'by pressing ESC';
} else if (reason === ModalDismissReasons.BACKDROP_CLICK) {
return 'by clicking on a backdrop';
} else {
return `with: ${reason}`;
}
}
}


Below Given Is HTML code



  <ng-template #content let-d="dismiss">
<form class="form" [formGroup]="profileForm" (ngSubmit)="onSubmit()" autocomplete="off" >
<div class="modal-header">
<h4 class="modal-title">Add New Role</h4>
<button type="button" #clsbtn class="close" aria-label="Close" (click)="d('Cross click')">
<span aria-hidden="true">&times;</span>
</button>
</div>

<div class="modal-body" *ngIf="is_shown==true">
<div class="modal-body">
<div class="col-md-5">
<div class="card-content">
<div class="input-group">
<span class="input-group-addon">
<i class="material-icons">face</i>
</span>
<div class="form-group"><input type="text" #rolename formControlName="rolename" class="form-control" placeholder="RoleName..." required/><span class="material-input"></span></div>
<div *ngIf="profileForm.get('rolename').invalid && profileForm.get('rolename').touched" class="alert alert-danger">
<div *ngIf="profileForm.get('rolename').errors.required">
RoleName is required.
</div>
<div *ngIf="profileForm.get('rolename').errors.minlength">
RoleName must be at least 4 characters long.
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<!--<button type="button" class="btn btn-light" (click)="d('Close click')">Close</button>-->
<button class="btn btn-danger btn-round" style="position:relative;right:60px" [disabled]="profileForm.invalid">
<i class="material-icons">check</i> Add
</button>
</div>
</form>
</ng-template>









share|improve this question
























  • no i havent will it work?
    – Talha Sarwar
    Nov 22 at 13:50










  • @PierreDuc i tried it and i got Cannot read property 'nativeElement' of undefined
    – Talha Sarwar
    Nov 22 at 13:52






  • 1




    did you try accessing it inside ngAfterViewInit() Life Cycle method.
    – Suresh Kumar Ariya
    Nov 22 at 13:54










  • yes indeed i have but the same issue
    – Talha Sarwar
    Nov 22 at 13:57










  • Where is the dataTable in your html?
    – Yousef khan
    Nov 22 at 14:13













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am working on an Angular-6 Project. I have created a form inside ngxbootstrap modal which is working fine. That form has various input elements I want to access few of these elements but the issue is whenever I try to access those elements using @viewchild, the result is undefined which is basically due to the fact that those elements don't exist on DOM.So, Is there any way I can access them below is my code...



@Component({
selector: 'app-roles',
templateUrl: './roles.component.html',
styleUrls: ['./roles.component.scss'],
providers:[NgbActiveModal],
})
export class RolesComponent implements OnInit,AfterViewInit {
@ViewChild('dataTable') table:ElementRef;
@ViewChild('rolename') rolename:ElementRef; //Here it shows undefined
dataTable:any;
roleref:any;
error_array=new Array();
all_roles=new Array();
added:boolean;
closeResult: string;
modalRef: NgbModalRef;
is_shown:boolean;


profileForm=new FormGroup({
rolename:new FormControl('',[Validators.required,Validators.minLength(4)])
});
constructor(private roleservice:RolesService,private fb:FormBuilder,private
modalService: NgbModal,public activeModal: NgbActiveModal)
{
}

ngOnInit() {
this.dataTable=$(this.table.nativeElement);
this.dataTable.dataTable();

}

ngAfterViewInit() {
}

open(content,form:NgForm) {
this.is_shown=true;
this.modalRef = this.modalService.open(content,{
size: "lg",
centered: false,
backdrop: 'static'});
this.modalRef.result.then((result) => {
this.closeResult = `Closed with: ${result}`;
}, (reason) => {
this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
});
}

private getDismissReason(reason: any): string {
this.is_shown=false;
this.profileForm.reset();
if (reason === ModalDismissReasons.ESC) {
return 'by pressing ESC';
} else if (reason === ModalDismissReasons.BACKDROP_CLICK) {
return 'by clicking on a backdrop';
} else {
return `with: ${reason}`;
}
}
}


Below Given Is HTML code



  <ng-template #content let-d="dismiss">
<form class="form" [formGroup]="profileForm" (ngSubmit)="onSubmit()" autocomplete="off" >
<div class="modal-header">
<h4 class="modal-title">Add New Role</h4>
<button type="button" #clsbtn class="close" aria-label="Close" (click)="d('Cross click')">
<span aria-hidden="true">&times;</span>
</button>
</div>

<div class="modal-body" *ngIf="is_shown==true">
<div class="modal-body">
<div class="col-md-5">
<div class="card-content">
<div class="input-group">
<span class="input-group-addon">
<i class="material-icons">face</i>
</span>
<div class="form-group"><input type="text" #rolename formControlName="rolename" class="form-control" placeholder="RoleName..." required/><span class="material-input"></span></div>
<div *ngIf="profileForm.get('rolename').invalid && profileForm.get('rolename').touched" class="alert alert-danger">
<div *ngIf="profileForm.get('rolename').errors.required">
RoleName is required.
</div>
<div *ngIf="profileForm.get('rolename').errors.minlength">
RoleName must be at least 4 characters long.
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<!--<button type="button" class="btn btn-light" (click)="d('Close click')">Close</button>-->
<button class="btn btn-danger btn-round" style="position:relative;right:60px" [disabled]="profileForm.invalid">
<i class="material-icons">check</i> Add
</button>
</div>
</form>
</ng-template>









share|improve this question















I am working on an Angular-6 Project. I have created a form inside ngxbootstrap modal which is working fine. That form has various input elements I want to access few of these elements but the issue is whenever I try to access those elements using @viewchild, the result is undefined which is basically due to the fact that those elements don't exist on DOM.So, Is there any way I can access them below is my code...



@Component({
selector: 'app-roles',
templateUrl: './roles.component.html',
styleUrls: ['./roles.component.scss'],
providers:[NgbActiveModal],
})
export class RolesComponent implements OnInit,AfterViewInit {
@ViewChild('dataTable') table:ElementRef;
@ViewChild('rolename') rolename:ElementRef; //Here it shows undefined
dataTable:any;
roleref:any;
error_array=new Array();
all_roles=new Array();
added:boolean;
closeResult: string;
modalRef: NgbModalRef;
is_shown:boolean;


profileForm=new FormGroup({
rolename:new FormControl('',[Validators.required,Validators.minLength(4)])
});
constructor(private roleservice:RolesService,private fb:FormBuilder,private
modalService: NgbModal,public activeModal: NgbActiveModal)
{
}

ngOnInit() {
this.dataTable=$(this.table.nativeElement);
this.dataTable.dataTable();

}

ngAfterViewInit() {
}

open(content,form:NgForm) {
this.is_shown=true;
this.modalRef = this.modalService.open(content,{
size: "lg",
centered: false,
backdrop: 'static'});
this.modalRef.result.then((result) => {
this.closeResult = `Closed with: ${result}`;
}, (reason) => {
this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
});
}

private getDismissReason(reason: any): string {
this.is_shown=false;
this.profileForm.reset();
if (reason === ModalDismissReasons.ESC) {
return 'by pressing ESC';
} else if (reason === ModalDismissReasons.BACKDROP_CLICK) {
return 'by clicking on a backdrop';
} else {
return `with: ${reason}`;
}
}
}


Below Given Is HTML code



  <ng-template #content let-d="dismiss">
<form class="form" [formGroup]="profileForm" (ngSubmit)="onSubmit()" autocomplete="off" >
<div class="modal-header">
<h4 class="modal-title">Add New Role</h4>
<button type="button" #clsbtn class="close" aria-label="Close" (click)="d('Cross click')">
<span aria-hidden="true">&times;</span>
</button>
</div>

<div class="modal-body" *ngIf="is_shown==true">
<div class="modal-body">
<div class="col-md-5">
<div class="card-content">
<div class="input-group">
<span class="input-group-addon">
<i class="material-icons">face</i>
</span>
<div class="form-group"><input type="text" #rolename formControlName="rolename" class="form-control" placeholder="RoleName..." required/><span class="material-input"></span></div>
<div *ngIf="profileForm.get('rolename').invalid && profileForm.get('rolename').touched" class="alert alert-danger">
<div *ngIf="profileForm.get('rolename').errors.required">
RoleName is required.
</div>
<div *ngIf="profileForm.get('rolename').errors.minlength">
RoleName must be at least 4 characters long.
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<!--<button type="button" class="btn btn-light" (click)="d('Close click')">Close</button>-->
<button class="btn btn-danger btn-round" style="position:relative;right:60px" [disabled]="profileForm.invalid">
<i class="material-icons">check</i> Add
</button>
</div>
</form>
</ng-template>






angular viewchild






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 at 13:28









priyanshi srivastava

424112




424112










asked Nov 22 at 13:25









Talha Sarwar

11




11












  • no i havent will it work?
    – Talha Sarwar
    Nov 22 at 13:50










  • @PierreDuc i tried it and i got Cannot read property 'nativeElement' of undefined
    – Talha Sarwar
    Nov 22 at 13:52






  • 1




    did you try accessing it inside ngAfterViewInit() Life Cycle method.
    – Suresh Kumar Ariya
    Nov 22 at 13:54










  • yes indeed i have but the same issue
    – Talha Sarwar
    Nov 22 at 13:57










  • Where is the dataTable in your html?
    – Yousef khan
    Nov 22 at 14:13


















  • no i havent will it work?
    – Talha Sarwar
    Nov 22 at 13:50










  • @PierreDuc i tried it and i got Cannot read property 'nativeElement' of undefined
    – Talha Sarwar
    Nov 22 at 13:52






  • 1




    did you try accessing it inside ngAfterViewInit() Life Cycle method.
    – Suresh Kumar Ariya
    Nov 22 at 13:54










  • yes indeed i have but the same issue
    – Talha Sarwar
    Nov 22 at 13:57










  • Where is the dataTable in your html?
    – Yousef khan
    Nov 22 at 14:13
















no i havent will it work?
– Talha Sarwar
Nov 22 at 13:50




no i havent will it work?
– Talha Sarwar
Nov 22 at 13:50












@PierreDuc i tried it and i got Cannot read property 'nativeElement' of undefined
– Talha Sarwar
Nov 22 at 13:52




@PierreDuc i tried it and i got Cannot read property 'nativeElement' of undefined
– Talha Sarwar
Nov 22 at 13:52




1




1




did you try accessing it inside ngAfterViewInit() Life Cycle method.
– Suresh Kumar Ariya
Nov 22 at 13:54




did you try accessing it inside ngAfterViewInit() Life Cycle method.
– Suresh Kumar Ariya
Nov 22 at 13:54












yes indeed i have but the same issue
– Talha Sarwar
Nov 22 at 13:57




yes indeed i have but the same issue
– Talha Sarwar
Nov 22 at 13:57












Where is the dataTable in your html?
– Yousef khan
Nov 22 at 14:13




Where is the dataTable in your html?
– Yousef khan
Nov 22 at 14:13












2 Answers
2






active

oldest

votes

















up vote
0
down vote













dataTable I think is not defined on the view.



rolename is define inside a *ngIf and maybe you'll try to access it when the condition is false.



You could try something like this:



private yourElement: ElementRef;

@ViewChild('elementName') set elementName(content: ElementRef) {
this.yourElement = content;
}


and use yourElement when available in your component.






share|improve this answer





















  • Sir datatable is working fine i am not having any issue with it i am having issues with rolename
    – Talha Sarwar
    Nov 22 at 14:52










  • Ok, the second part for rolename is valid?
    – ptesser
    Nov 22 at 14:58












  • Yes sir but your solution dint work :( still getting undefined
    – Talha Sarwar
    Nov 22 at 14:59


















up vote
0
down vote













It's not possible because ngxbootstrap modal attaches dynamically your template content into your component when you call open method from the modalservice.



ngOnInit or ngAfterViewInit won't allow you to retrieve the reference of your embeded elements, because your elements aren't inserted to your DOM.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53432017%2funable-to-get-the-reference-of-the-elements-inside-modal-using-viewchild%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    dataTable I think is not defined on the view.



    rolename is define inside a *ngIf and maybe you'll try to access it when the condition is false.



    You could try something like this:



    private yourElement: ElementRef;

    @ViewChild('elementName') set elementName(content: ElementRef) {
    this.yourElement = content;
    }


    and use yourElement when available in your component.






    share|improve this answer





















    • Sir datatable is working fine i am not having any issue with it i am having issues with rolename
      – Talha Sarwar
      Nov 22 at 14:52










    • Ok, the second part for rolename is valid?
      – ptesser
      Nov 22 at 14:58












    • Yes sir but your solution dint work :( still getting undefined
      – Talha Sarwar
      Nov 22 at 14:59















    up vote
    0
    down vote













    dataTable I think is not defined on the view.



    rolename is define inside a *ngIf and maybe you'll try to access it when the condition is false.



    You could try something like this:



    private yourElement: ElementRef;

    @ViewChild('elementName') set elementName(content: ElementRef) {
    this.yourElement = content;
    }


    and use yourElement when available in your component.






    share|improve this answer





















    • Sir datatable is working fine i am not having any issue with it i am having issues with rolename
      – Talha Sarwar
      Nov 22 at 14:52










    • Ok, the second part for rolename is valid?
      – ptesser
      Nov 22 at 14:58












    • Yes sir but your solution dint work :( still getting undefined
      – Talha Sarwar
      Nov 22 at 14:59













    up vote
    0
    down vote










    up vote
    0
    down vote









    dataTable I think is not defined on the view.



    rolename is define inside a *ngIf and maybe you'll try to access it when the condition is false.



    You could try something like this:



    private yourElement: ElementRef;

    @ViewChild('elementName') set elementName(content: ElementRef) {
    this.yourElement = content;
    }


    and use yourElement when available in your component.






    share|improve this answer












    dataTable I think is not defined on the view.



    rolename is define inside a *ngIf and maybe you'll try to access it when the condition is false.



    You could try something like this:



    private yourElement: ElementRef;

    @ViewChild('elementName') set elementName(content: ElementRef) {
    this.yourElement = content;
    }


    and use yourElement when available in your component.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 22 at 14:47









    ptesser

    21449




    21449












    • Sir datatable is working fine i am not having any issue with it i am having issues with rolename
      – Talha Sarwar
      Nov 22 at 14:52










    • Ok, the second part for rolename is valid?
      – ptesser
      Nov 22 at 14:58












    • Yes sir but your solution dint work :( still getting undefined
      – Talha Sarwar
      Nov 22 at 14:59


















    • Sir datatable is working fine i am not having any issue with it i am having issues with rolename
      – Talha Sarwar
      Nov 22 at 14:52










    • Ok, the second part for rolename is valid?
      – ptesser
      Nov 22 at 14:58












    • Yes sir but your solution dint work :( still getting undefined
      – Talha Sarwar
      Nov 22 at 14:59
















    Sir datatable is working fine i am not having any issue with it i am having issues with rolename
    – Talha Sarwar
    Nov 22 at 14:52




    Sir datatable is working fine i am not having any issue with it i am having issues with rolename
    – Talha Sarwar
    Nov 22 at 14:52












    Ok, the second part for rolename is valid?
    – ptesser
    Nov 22 at 14:58






    Ok, the second part for rolename is valid?
    – ptesser
    Nov 22 at 14:58














    Yes sir but your solution dint work :( still getting undefined
    – Talha Sarwar
    Nov 22 at 14:59




    Yes sir but your solution dint work :( still getting undefined
    – Talha Sarwar
    Nov 22 at 14:59












    up vote
    0
    down vote













    It's not possible because ngxbootstrap modal attaches dynamically your template content into your component when you call open method from the modalservice.



    ngOnInit or ngAfterViewInit won't allow you to retrieve the reference of your embeded elements, because your elements aren't inserted to your DOM.






    share|improve this answer

























      up vote
      0
      down vote













      It's not possible because ngxbootstrap modal attaches dynamically your template content into your component when you call open method from the modalservice.



      ngOnInit or ngAfterViewInit won't allow you to retrieve the reference of your embeded elements, because your elements aren't inserted to your DOM.






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        It's not possible because ngxbootstrap modal attaches dynamically your template content into your component when you call open method from the modalservice.



        ngOnInit or ngAfterViewInit won't allow you to retrieve the reference of your embeded elements, because your elements aren't inserted to your DOM.






        share|improve this answer












        It's not possible because ngxbootstrap modal attaches dynamically your template content into your component when you call open method from the modalservice.



        ngOnInit or ngAfterViewInit won't allow you to retrieve the reference of your embeded elements, because your elements aren't inserted to your DOM.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 22 at 16:24









        Nicolas Law-Dune

        7891424




        7891424






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53432017%2funable-to-get-the-reference-of-the-elements-inside-modal-using-viewchild%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Lallio

            Unable to find Lightning Node

            Futebolista