Components: Adding mat-option dynamically to mat-select from .ts file(Using JavaScript)

Created on 16 Mar 2018  路  5Comments  路  Source: angular/components

Bug, feature request, or proposal:

Adding or Creating 'mat-option' dynamically to 'mat-select' from .ts file(using JavaScript).

Is it possible to create or add 'mat-option' dynamically?

What is the expected behavior?

Need to create or add 'mat-option' dynamically from .ts file using JavaScript.

What is the current behavior?

Currently we can add 'mat-option' using *ngFor.

"

{{topping}}

"

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Angular: 5.2.3
angular-material: 5.1.1
Windows 10
typescript: 2.7.1
All Browsers

Most helpful comment

Yes it's possible.

this.toppingList.unshift("newValue"); or this.toppingList.push("newValue");

All 5 comments

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._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jelbourn picture jelbourn  路  3Comments

RoxKilly picture RoxKilly  路  3Comments

kara picture kara  路  3Comments

michaelb-01 picture michaelb-01  路  3Comments

crutchcorn picture crutchcorn  路  3Comments