假设我有一个指令,其中包含一个用户可以输入水果名称的表单。如何在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