Solved

AngularJS need to set default in drop down select

Posted on 2013-12-10
2
26,165 Views
1 Endorsement
Last Modified: 2013-12-10
I have the following select in my HTML

<select ng-model="atcStatusTaskList" ng-options="s.name for s in statusTaskList"></select>

It is filled with this in the controller

   $scope.statusTaskList = [
        { name: 'Open', value: '1' },
        { name: 'In Progress', value: '2' },
        { name: 'Complete', value: '3' },
        { name: 'Deleted', value: '4' },
    ];

When it fills up the select there is a blank, I want it to default to 'Open'.  

I also need to fill it later when the value changes ie 1,2,3,4
1
Comment
Question by:charlesbaldo
2 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39709776
Test page : http://jsfiddle.net/j5S7y/

You need to use a different model for the select:

<select ng-model="atcStatusTasks" ng-options="s.name for s in statusTaskList"></select>

Open in new window

function myCtrl($scope) {
     $scope.statusTaskList = [
        { name: 'Open', value: '1' },
        { name: 'In Progress', value: '2' },
        { name: 'Complete', value: '3' },
        { name: 'Deleted', value: '4' },
    ];
    $scope.atcStatusTasks = $scope.statusTaskList[0]; // 0 -> Open 
}

Open in new window

1
 

Author Closing Comment

by:charlesbaldo
ID: 39709905
Excellent Thanks Again
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now