Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9152965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:10:52+00:00 2026-06-17T12:10:52+00:00

This must have been already done, and I am missing something about how Angular

  • 0

This must have been already done, and I am missing something about how Angular works on that point.

In short, I have <select ng-model><option ng-repeat/></select> and I don’t know how to give it a default value at page load.

View:

<div ng-ctrl="MyCtrl">
  <form ng-submit="submitChoice()">
    <select ng-model='choice'>
      <option ng-repeat='choice in choices' value='{{choice.id}}'>{{choice.id}}</option>
    </select>
  </form>
</div>

Way 1: When user updates the view (select the ‘choice’ he wants), the $scope used in MyCtrl gets it and I can perform whatever I want with it:

Way 2: But if, the other way round, I want to programmatically set the default value for the choices from the controller (at start), it can’t change the value displayed:

function MyCtrl ($scope) {
  $scope.submitChoice = function() {return;}; // Way1: OK!
  $scope.choice = choice4;                    // Way2: Doesn't change the view!!
}

I guess it’s because each element in ng-repeat has its own scope (fyi if I hardcode options in view instead of a ng-repeat, it works well).

In way 1 the inner scope selected by the use emits choice to the upper scope, if I understand well. But I have no idea how to do way 2.

Is it doable in a simple way? Is a directive necessary?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:10:53+00:00Added an answer on June 17, 2026 at 12:10 pm

    You would be better off using the ng-options directive with the select directive. Using select + ngRepeat has all sort of limitations and is better avoided. Is there any particular reason for generating options with ngRepeat?

    If you could share more code (especially the structure of your data model) I might be able to provide more info.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to believe that this question must have been already answered multiple times,
I know that this question must have been answered plenty of times already, but
I know that this question must have been asked and answered a million times,
I am sure that this kind of questions must have been asked before, but
I know this subject has been done already over and over. but... i must
I'm pretty sure this must have been here already, but I didn't find much
I thought this must already have been answered, but I couldn't find anything on
(I'm sure this must have been answered on this site already, but search gets
This must have been answered previously, but my Google powers are off today and
I'm sure this must have been covered before because I'm sure I'm not the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.