Adding or Creating 'mat-option' dynamically to 'mat-select' from .ts file(using JavaScript).
Is it possible to create or add 'mat-option' dynamically?
Need to create or add 'mat-option' dynamically from .ts file using JavaScript.
Currently we can add 'mat-option' using *ngFor.
"
Angular: 5.2.3
angular-material: 5.1.1
Windows 10
typescript: 2.7.1
All Browsers
Yes it's possible.
this.toppingList.unshift("newValue"); or this.toppingList.push("newValue");
Yes, we can add values to the toppingList array. But, I need to add "mat-option" element to the template using JavaScript.
@ramkumar93 I'm not sure to understand...
You have a select element, with multiples options (equals to toppingList size) generated by the for loop. If you want to add another option to this select just grow your list (toppingList here).
If it's not your goal, describe it with an example or a picture of what you want to achieve. And better ask it on StackOverflow :+1:
Please keep GitHub issues for bug reports / feature requests. Better avenues for troubleshooting / questions are stack overflow, gitter, mailing list, etc.
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
_This action has been performed automatically by a bot._
Most helpful comment
Yes it's possible.
this.toppingList.unshift("newValue");orthis.toppingList.push("newValue");