1

I have a Select element like this

 <select class="form-control" id="designation" ng-model="employee.designation" ng-init="select Designation = options[0]" ng-options="d for d in designations" required></select>

Now i want to set the initial value for this element like 'Select Designation' to be the default value. how can i achieve this? I am able to bind the values but i am not able to set the default value, can anyone help me !!!

the controller code is this

(function () {
            var app = angular.module('mainApp', []);
            app.controller('employeeCtrl', ['$scope', '$http', function ($scope, $http) {
                this.employee = {};

                $http.get('/Data/Designation.json').success(function (data) {
                    debugger;
                    $scope.designations = data;
                }).error(function () {
                    alert('error !!!');
                });
                $scope.formSubmit = function () {
                    debugger;
                };
            }]);
        })();
Lijin Durairaj
  • 4,910
  • 15
  • 52
  • 85
  • 3
    `ng-init="select Designation = options[0]"` - What is `select Designation` supposed to do? - You probably want `employee.designation =designations[0]` – tymeJV Jan 10 '17 at 16:38
  • agree with @tymeJV , but you have to add this line inside `success` callback of `ajax` – Pankaj Parkar Jan 11 '17 at 07:29

1 Answers1

0

just for the people who got stuck with this same scenario, i got it resolved by adding default value to the file from where i am retrieving data and using the ng-init tag like this

ng-init="designations[0]"
Lijin Durairaj
  • 4,910
  • 15
  • 52
  • 85