我在学习AngularJS的过程中遇到了许多承诺,迄今为止它一直很好。现在,我想了解更多关于使用AngularJS可选库resource.js的信息。但是,我遇到了很多让我困惑的例子。例如,promise框架基本上就是这个例子。
//post method to server
$http.post('api/school',newStudent).then(fetchStudents).then(function(response){
//do something
}, function(error){
//do something
});
和这样的另一个例子假设我们有一个表厂
List.save(self.newStudent).$promise.then(fetchStudents).then(function(){
self.newStudent = {};
});
所以我的问题是为什么使用$答应么?它有什么用处?这在我正在使用的书中没有真正解释,我对什么时候使用它有困惑。任何明确的解释将不胜感激。由于
你可以成为一个承诺忍者看完这个: http://www.webdeveasy.com/javascript -promises和 - angularjs-q-服务/ – Ladmerc