локальный сервер не заполнен ng-repeat

0

Я создал локальный файл db.json, который выглядит так:

{
  "project_topics": [
"- Any -",
"Access for disadvantaged",
"Agriculture, forestry and fisheries",
"Animal welfare",
"Energy and resources",
"Enhance social inclusion, equal opportunities and participation in sports",
"Enterprise, industry and SMEs (incl. entrepreneurship)",
"Entrepreneurial learning - entrepreneurship education",
"Environment and climate change" 
]}

Я хочу заполнить ввод с помощью ng-repeat, и я делаю это так:

<label class="item item-select " id="findYourProject-select3">
            <span class="input-label">type of project</span>
            <select ng-repeat="topic in project_topics"></select>
        </label>

Вход не заполняется. Что мне следует учитывать?

  • 0
    Что вы пробовали?
  • 0
    Я скопировал неправильный сегмент кода. Я обновил свой вопрос.
Показать ещё 1 комментарий
Теги:
angularjs-ng-repeat

2 ответа

0
Лучший ответ

Вы должны указать ng-repeat для options не select

см. plunker json из внешнего файла http://plnkr.co/edit/tpl:8rFfZljYNl3z1A4LKSL2?p=preview

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

app.controller('MainCtrl', function($scope,$http) {
  $scope.data = {
  "project_topics": [
"- Any -",
"Access for disadvantaged",
"Agriculture, forestry and fisheries",
"Animal welfare",
"Energy and resources",
"Enhance social inclusion, equal opportunities and participation in sports",
"Enterprise, industry and SMEs (incl. entrepreneurship)",
"Entrepreneurial learning - entrepreneurship education",
"Environment and climate change" 
]};
       /* var urlPath = 'db.json';
      $http.get(urlPath).then(function(response) {
       $scope.data = response.data;
       
      }, function(error) {
       
      });*/
  
  
  
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="plunker" ng-controller="MainCtrl">
 <select  ng-model="singleSelect">
     <option  ng-repeat="topic in data.project_topics">{{topic}}</option>
    </select>
  
  </body>
  • 0
    Этот подход явно работает, но я хочу, чтобы мои данные были в файле db.json, а не в моем контроллере
  • 0
    см. закомментированный код сверху кода, он будет работать для внешнего файла JSON
Показать ещё 2 комментария
0
<label class="item item-select " id="findYourProject-select3">
  <span class="input-label">type of project</span>
  <select>
    <option ng-repeat="topic in project_topics" value="{{topic}}">{{topic}}</option>
  </select>
</label>

Вы хотите повторить эту option. Не select.

Ещё вопросы

Сообщество Overcoder
Наверх
Меню