各項目の説明で入力して調べます。サービス内のconsoleステートメントは望ましい出力を示しますが、ctrlの約束はエラーが発生した場所です。私は何が欠けていますか?TypeError:プロパティの読み込みが未定義
NarrowItDownController.$inject=['MenuSearchService'];
function NarrowItDownController(MenuSearchService) {
var ctrl = this;
ctrl.searchTerm = "";
ctrl.found=[];
ctrl.searchlist = function() {
if (ctrl.searchTerm.length > 0) {
console.log(ctrl.searchTerm);
var promise = MenuSearchService.getMatchedMenuItems(ctrl.searchTerm);
promise.then(function (result) {
ctrl.found = result;
}).catch(function (error) {
console.log("something went wrong!!!");
});
}
};
}
MenuSearchService.$inject = ['$http'];
function MenuSearchService($http) {
var service= this;
var found = [];
service.getMatchedMenuItems = function (searchTerm) {
var response = $http({
method: "GET",
url: ("https://davids-restaurant.herokuapp.com/menu_items.json")
}).then(function (response) {
for (var i = 0; i < response.data.menu_items.length; i++) {
if (response.data.menu_items[i]
.description.toLowerCase().indexOf(searchTerm)>-1) {
found.push(response.data.menu_items[i]);
}
}
console.log(found);
return found;
}, function() {
console.log('error');
});
};
}
})();
インデントは恐ろしいです...あなたは1つ以上の閉じ括弧と括弧を開いたものよりも持っています。 – trincot