Hi I am developing web application in angularjs. I am trying to bind data to drodpown. I am making ajax call to get data from server. I am getting error Cannot read property 'length' of undefined. I am making get request. This is my api. http://192.168.0.213:1234/api/Customer/Nationalities
Above api will return
{"status":"Success","msg":"Success","code":"200","data":[{"ID":1,"Nationality":"indian"},{"ID":2,"Nationality":"england"}]}
I am binding using js as below.
var url = cfg.Baseurl;
var nationality = new Array();
$http.get(url + 'api' + '/Customer/' + 'Nationalities').success(function (data) {
$.map(data.data.Nationality, function (item) {
nationality.push(item);
console.log(item);
});
$scope.nationalityList = nationality;
}).error(function (status) {
});
This is my html code.
<select ng-model="user.nationality" id="brand" ng-options="user.nationality for user in nationalityList" required>
<option value="" label="Select">Select</option>
</select>
I ended up with Cannot read property 'length' of undefined error. Any help would be appreciated. Thank you.
$scope.nationalityList = []