【发布时间】:2015-12-03 08:35:22
【问题描述】:
我想知道在存储到 Firebase 时如何在 Angular 控制器中构建实际的推送和更新方法。现在我认为有很多重复的代码和糟糕的结构。它看起来像这样:
app.controller( "myController", [ "$scope", "$routeParams", function( $scope, $routeParams ) {
$scope.id = $routeParams.id;
$scope.save = function() {
if( $scope.id ) {
// Update
}
else {
// Save
}
}
} ] );
update 和 save 之间的唯一区别是使用 Firebase 存储数据的方法(推送/更新)。否则存储的对象几乎相同,并且回调的处理方式相同。这给出了很多重复的代码。我将如何以一种好的方式来构建它以防止重复代码?
【问题讨论】:
标签: javascript angularjs firebase angularfire angular-routing