假設我有一個指令,其中包含一個用戶可以輸入水果名稱的表單。如何在angularjs中處理控制器中的數據?
- 我有一個FruitFindController。用戶輸入水果名稱「Apple」,點擊提交給控制器的按鈕。
- 控制器調用服務「GetFruitInfo(fruit)」並傳入「Apple」作爲參數。
- 一旦收到信息,它應該調用一個方法「addToListAndDoStuff()」,以便將fruitinfo添加到列表中。
我的問題是,在我的FruitFindController(假設fruitFinder是服務)...
$scope.GetFruitInfo = function() {
$scope.foundFruit = fruitFinder.GetFruitInfo($scope.fruitField);
// should alert "Found Fruit" and call addToListAndDoStuff() method to add the foundFruit information to the list managed by another directive, "FruitList".
}
什麼是「等待信息的最佳方式做之前存入$ scope.foundFruit下方彈出警告框的任何代碼?
是您的fruitFinder返回一個承諾? – ivarni
FruitFinder服務如何獲得水果信息? – callmekatootie