⚠️ This lesson is retired and might contain outdated information.

ng-model and ng-for with Select and Option elements [obsolete]

John Lindquist
InstructorJohn Lindquist
Share this video with your friends

Social Share Links

Send Tweet
Published 9 years ago
Updated 6 years ago

** This lesson is obsolete.**

You can use Select and Option elements in combination with ng-for and ng-model to create mini-forms that change your data as you make a selection.

To make this letter that we pass into our pipe dynamic, let's go ahead and add a select with some options. For our select, we want to use ngModel, so we'll go ahead and import the form directives, which has ngModel in it, and make sure that we use the form directives in here.

Then we can use our ng-model and set it to something like selected letter. In our options, we'll go ahead and loop through, using ng-4, and grab each letter of letters. We need to set up some letters for that to actually use.

We'll say E, C, and S. Then to display the letters, we'll come in here and display each letter in the options. Hit save, and you can see we now have the letters inside of our switcher. Because this is blank when it starts, let's go ahead and set the selected letter to something right away, like E is fine.

Hit save, and you can see we have all our options here. To make this letter dynamic, we'll just go ahead and drop in our selected letter. Instead of a string, it's actually pointing to what's ever selected using our ngModel.

I can come in, select C, select S, and we're good to go.

egghead
egghead
~ 25 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today