я хочу добавить значения для поля выбора с помощью скрипта. // HTML-код

<html>
 <body>
 <p>
    <select ng-model="selectedValue" ng-option="c1.name in c1 in c in personInfo.city"></select>
    </p>
 </body>
 >/html>

// скрипт

$scope.personInfo = {};

            $scope.personInfo.city = [
            {name:"Select City Name", value:""},
            {name:"Pune", value:"P"},
            {name:"Mumbai", value:"M"},
            {name:"Delhi", value:"D"},
            {name:"Kerla", value:"K"},
            ];
-2
chetan.mohol 27 Ноя 2017 в 09:51

1 ответ

Лучший ответ

Ваш вариант должен быть ng-options="item as item.name for item in personInfo.city"

var myApp = angular.module('myApp',[]);
myApp.controller('MyCtrl',function($scope, $timeout) {
$scope.personInfo = {};

            $scope.personInfo.city = [
            {name:"Select City Name", value:""},
            {name:"Pune", value:"P"},
            {name:"Mumbai", value:"M"},
            {name:"Delhi", value:"D"},
            {name:"Kerla", value:"K"},
            ];
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.min.js"></script>
<div ng-app="myApp" ng-controller="MyCtrl">
<select ng-options="item as item.name for item in personInfo.city" ng-model="selected"></select>
</div>
1
jitender 27 Ноя 2017 в 06:59