2016-07-25 38 views
0

我创建了一个本地文件db.json看起来像这样:本地服务器不填充NG重复

{ 
    "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-重复输入和我做它像这样:

<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

我复制了一段错误的代码。我更新了我的问题。 – NewLuckyProgramer

+0

使用'ng-options' http://jsfiddle.net/2JWb2/5/ –

回答

0

你必须给NG重复为optionsselect

看到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文件中,而不是在我的控制器 – NewLuckyProgramer

+0

中查看注释代码上面的代码,它将工作的外部json文件 –

+0

@NewLuckyProgramer看到更新的答案,创建的plunker代码,从外部json文件加载数据 –

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