Permalink
Browse files

Step 5 - restangular

  • Loading branch information...
Fodoj committed Apr 16, 2015
1 parent 67e3dc7 commit a0629f595db4d49c7e7c956ffcefe1cdb1050be0
Showing with 18 additions and 4 deletions.
  1. +3 −1 src/app/index.js
  2. +5 −2 src/app/main/transactions.controller.js
  3. +10 −1 src/components/transactions_store.service.js
@@ -1,7 +1,9 @@
'use strict';

angular.module('ngmkdev', ['restangular', 'ui.router', 'ui.bootstrap'])
.config(function ($stateProvider, $urlRouterProvider) {
.config(function ($stateProvider, $urlRouterProvider, RestangularProvider) {
RestangularProvider.setBaseUrl("http://localhost:4567");

$stateProvider
.state('transactions', {
url: "/",
@@ -1,8 +1,9 @@
angular.module('ngmkdev').controller('TransactionsCtrl', function($scope, TransactionsStore) {
this.transactions = TransactionsStore.transactions

TransactionsStore.loadTransactions();

this.addTransaction = function() {
this.transactions.push(this.newTransaction);
TransactionsStore.addTransaction(this.newTransaction);
this.resetTransaction();
}

@@ -13,6 +14,8 @@ angular.module('ngmkdev').controller('TransactionsCtrl', function($scope, Transa
description: null
}
}
this.transactions = TransactionsStore.transactions;
this.resetTransaction();

});

@@ -1,6 +1,15 @@
angular.module('ngmkdev').factory('TransactionsStore', function() {
angular.module('ngmkdev').factory('TransactionsStore', function(Restangular) {
return {
transactions: [],
loadTransactions: function() {
this.transactions = Restangular.all('transactions').getList().$object;
},
addTransaction: function(transaction) {
var that = this;
return Restangular.all('transactions').post({transaction: transaction}).then(function() {
that.transactions.push(transaction);
})
},
sum: function() {
var sum = 0;
this.transactions.forEach(function(el) {

0 comments on commit a0629f5

Please sign in to comment.