使用Ajax回调进行角度形式重置 [英] Angular Form Resetting with Ajax Callbacks
本文介绍了使用Ajax回调进行角度形式重置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个基本表单,在提交时运行了一个角度 $ save
操作:
I have a basic form with an Angular $save
action run on submit:
app.controller 'MyThingCtrl', ($scope, MyThing) ->
this.addThing = ->
new MyThing(this.thing).$save(
(data) ->
console.log 'New Thing Saved'
$scope.things.push data
this.thing = {}
,(err) ->
console.log 'Error: ' + err
)
期望的是 this.thing
的表单将在成功时重置,但不是,因为此
不再引用以前的操作。
The expectation is that the form for this.thing
will be reset on success, but it isn't, as the this
no longer refers to what it did before.
推荐答案
虽然范围 c的范围在回调中已更改,但变量
事物
可通过 $ scope
由Angular提供:
While the scope of this
is changed inside the callback, the variable thing
is available via the $scope
variable provided by Angular:
app.controller 'MyThingCtrl', ($scope, MyThing) ->
this.addThing = ->
new MyThing(this.thing).$save(
(data) ->
console.log 'New Thing Saved'
$scope.things.push data
$scope.thing = {}
,(err) ->
console.log 'Error: ' + err
)
这篇关于使用Ajax回调进行角度形式重置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文