How To Auto Selected Value Angularjs
drop down are blank i want auto selected value Richard how do this, i am new in angular
Solution 2:
If you have the following...
<selectng-model="item"><optionvalue="1">Bob</option><optionvalue="2">James</option><optionvalue="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;
});
<scriptsrc="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script><divng-app="app"ng-controller="ctrl"><selectng-model="item"><optionvalue="1">Bob</option><optionvalue="2">James</option><optionvalue="3">Karl</option></select></div>
Solution 3:
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(){
}
}]);
<scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.min.js"></script><divng-app ="app"ng-controller="MainCtrl"><selectclass="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>
Solution 4:
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.
Solution 5:
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;
Post a Comment for "How To Auto Selected Value Angularjs"