在执行更新之前,我的索引视图正在从数据库中提取所有模型是否有任何方法可以确保这些操作是同步的。模型已更新并在刷新后显示在索引页面中是代码
app = angular.module('enterprise',["ngResource"])
.config(['$routeProvider','$locationProvider','$httpProvider', ($routeProvider,$locationProvider,provider )->
$locationProvider.html5Mode(true)
provider.defaults.headers.common['X-CSRF-Token'] = $('meta[name=csrf-token]').attr('content')
$routeProvider.when('/', {templateUrl: '<%=asset_path('list.html') %>', controller: AppCtrl})
$routeProvider.when('/new', {templateUrl: '<%=asset_path('edit.html') %>', controller: NewCtrl})
$routeProvider.when('/edit/:id', {templateUrl: '<%=asset_path('edit.html') %>', controller: EditCtrl})
$routeProvider.otherwise({redirectTo: '/'})
]
app.factory "People", ["$resource",($resource)->
$resource("/people/:id", {id:"@id"},{update: {method:"PUT"}}, {})
]
@AppCtrl=["$scope","People",($scope, People)->
$scope.crew = People.query()
]
@NewCtrl=["$scope","$location", "People",($scope, $location, People) ->
$scope.save = ->
person = People.save($scope.person)
$location.path("/")
]
@EditCtrl=["$scope", "$location", "$routeParams","People",($scope, $location, $routeParams, People)->
$scope.person = People.get({id:$routeParams.id})
$scope.save = ->
person = People.get({id:$routeParams.id }
, ->
person.name = $scope.person.name
person.description = $scope.person.description
person.$update()
)
$location.path("/")
]
在返回索引视图之前确保模型更新的任何建议