0

drop down are blank i want auto selected value Richard how do this, i am new in angular

  <select class="form-control" name="customer" id="customer" ng-model="postjobcustomerCtrl.selectedCustomer" ng-options="customer.full_name for customer in postjobcustomerCtrl.atlasCustomers  | filter:{full_name: Profile.full_name} track by customer.user_id"
ng-change="postjobcustomerCtrl.selectDefaultAddress()" required></select>

enter image description here

Adeel Khan
  • 129
  • 2
  • 13
  • 1
    Possible duplicate of [How to have a default option in Angular.js select box](http://stackoverflow.com/questions/18194255/how-to-have-a-default-option-in-angular-js-select-box) – Pritam Banerjee Nov 21 '16 at 17:53
  • add `$cope.postjobcustomerCtrl = {selectedCustomer = 'value'}` in ngController. – gaurav bhavsar Nov 21 '16 at 17:53

5 Answers5

0

You'll want to use Angular's ng-Init to set a selected value inline.

<select class="form-control" name="customer" id="customer" ng-model="postjobcustomerCtrl.selectedCustomer" ng-options="customer.full_name for customer in postjobcustomerCtrl.atlasCustomers  | filter:{full_name: Profile.full_name} track by customer.user_id"
ng-change="postjobcustomerCtrl.selectDefaultAddress()" ng-init="postjobcustomerCtrl.selectedCustomer = 'Richard'" required></select>
Daerik
  • 4,167
  • 2
  • 20
  • 33
0

In your postjobcustomerCtrl, initialize the select ng-model (postjobcustomerCtrl.selectedCustomer) with the id of Richard.

// angularjs controller

atlasCustomers = [{full_name : "Richard", user_id: 1}]        
postjobcustomerCtrl.selectedCustomer = atlasCustomers[0].atlasCustomers.user_id;
lealceldeiro
  • 14,342
  • 6
  • 49
  • 80
0

If you have the following...

<select ng-model="item">
  <option value="1">Bob</option>
  <option value="2">James</option>
  <option value="3">Karl</option>
</select>

... and you want James to be picked by default, then in the angular controller, you just do this:

$scope.item = 2;

Like so:

angular.module('app', [])
.controller('ctrl', function($scope){
  $scope.item = 2;
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
  <select ng-model="item">
    <option value="1">Bob</option>
    <option value="2">James</option>
    <option value="3">Karl</option>
  </select>
</div>
Samuel Reid
  • 1,756
  • 12
  • 22
0

All you need to do is to initialize your model with appropriate value("Richard") here to to get default value

var app = angular.module('app', []);

app.controller('MainCtrl', ['$scope', function ($scope, $http, uiGridConstants) {
  $scope.postjobcustomerCtrl ={};
  $scope.postjobcustomerCtrl.atlasCustomers =[{"full_name":"Richard"},{"full_name":"Colins"},{"full_name":"Steve"}];
  
  $scope.postjobcustomerCtrl.selectedCustomer =$scope.postjobcustomerCtrl.atlasCustomers[0]
  $scope.postjobcustomerCtrl.selectDefaultAddress =function(){
    
  }
  
}]);
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.min.js"></script>
<div ng-app ="app" ng-controller="MainCtrl">
  
   <select class="form-control" name="customer" id="customer" ng-model="postjobcustomerCtrl.selectedCustomer" ng-options="customer.full_name for customer in postjobcustomerCtrl.atlasCustomers"
ng-change="postjobcustomerCtrl.selectDefaultAddress()" required></select>
 
</div>


 
Vicky Kumar
  • 1,358
  • 1
  • 14
  • 26
0
 myApp.Controller("MyCltr, function($scope){
     // first fetch data from db
     // bind data to drop-down
     // then set selected value.
     $scope.postjobcustomerCtrl.selectedCustomer = "Richard";

});

And please make sure once your drop-down is binded with data after that set this value.