0
我正在使用angular-fullstack来创建应用程序。在我的应用程序,我使用Yelp API来获取搜索结果,我想在一个变量来存储(注:this.searchTerm通过一个NG-模型改变了HTML):Angular 2 Promises?
'use strict';
(function() {
class MainController {
constructor($http) {
this.$http = $http;
this.awesomeThings = [];
this.searchTerm = "";
this.data = [];
}
addThing() {
this.$http.get('/api/messages/city/' + this.searchTerm).success(function(res){
this.data = res;
});
};
}
angular.module('nightlifeApp').controller('MainController', MainController);})();
当我做所以,我得到一个错误,this.data没有定义。我知道这是对异步调用的性质做的,但我该如何解决这个问题?
由于
你如何调用addThing()方法? –
它通过在HTML中的按钮上单击鼠标来调用。 – svsav