当我刷新页面时,会出现正确的值。我希望在提交表单时自动更新“要点”列表。
全局@todone 是这样设置的,因为当我将其设置为“todone”时收到未定义的错误。它可能是无关的。
app.factory "To_done", ["$resource", ($resource) ->
$resource("/to_dones", {}, {update: {method: "PUT"}})
]
@MainCtrl = ["$scope", "To_done", ($scope, To_done) ->
$scope.to_dones = To_done.query()
$scope.addTodone = ->
@todone = To_done.save($scope.newTodone)
$scope.to_dones.push(@todone)
$scope.newTodone = {}
]
<div ng-controller="MainCtrl">
<form ng-submit="addTodone()">
<input type="text" ng-model="newTodone.gist">
<input type="submit" value="Add">
</form>
<ul>
<li ng-repeat="todone in to_dones">
{{todone.gist}}
</li>
</ul>
</div>