我嘗試了在stackoverflow上找到的示例,但在我看來,我仍然沒有收到任何信息。我可以在控制檯中看到articleIds,但在視圖中沒有任何內容。預先感謝您的幫助。無法綁定promise數據以在angularjs中查看
這裏是我的控制器:
export class MainController {
constructor ($http) {
'ngInject';
this.$http= $http;
this.apiHost = 'http://localhost:5005/api/articles';
this.getArticles();
}
getArticles() {
var vm = this;
this.$http.get(this.apiHost).then(function(result){
vm.articles = result.data;
vm.articles.forEach(function(item){
console.log(item.articleId);
});
});
}
}
這裏我的觀點:
<div class="form-group">
<label for="resumeId">Select article:</label>
<select class="form-control" id="resumeId">
<option ng-repeat="item in main.vm.articles" value="{{item.articleId}}">{{item.articleId }}</option>
</select></div>
我添加main.vm.articles,因爲路由使用controllerAs:'main' – Fred
您是否嘗試過'ng-repeat =「項目中的文章」'?從我可以說,應該工作。 – MeterLongCat
非常感謝! ng-repeat =「main.articles中的項目」的作品 – Fred