0

在执行更新之前,我的索引视图正在从数据库中提取所有模型是否有任何方法可以确保这些操作是同步的。模型已更新并在刷新后显示在索引页面中是代码

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("/")

]

在返回索引视图之前确保模型更新的任何建议

4

1 回答 1

0

放入资源$location.path("/")People回调函数。$resource动作有成功/失败回调。

于 2013-02-17T22:28:40.187 回答