Skip to content
This repository has been archived by the owner on Jun 10, 2022. It is now read-only.

Commit

Permalink
Step 5 - restangular
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill Shirinkin committed Apr 16, 2015
1 parent 67e3dc7 commit a0629f5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/app/index.js
@@ -1,7 +1,9 @@
'use strict'; 'use strict';


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

$stateProvider $stateProvider
.state('transactions', { .state('transactions', {
url: "/", url: "/",
Expand Down
7 changes: 5 additions & 2 deletions src/app/main/transactions.controller.js
@@ -1,8 +1,9 @@
angular.module('ngmkdev').controller('TransactionsCtrl', function($scope, TransactionsStore) { angular.module('ngmkdev').controller('TransactionsCtrl', function($scope, TransactionsStore) {
this.transactions = TransactionsStore.transactions
TransactionsStore.loadTransactions();


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


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


}); });

11 changes: 10 additions & 1 deletion src/components/transactions_store.service.js
@@ -1,6 +1,15 @@
angular.module('ngmkdev').factory('TransactionsStore', function() { angular.module('ngmkdev').factory('TransactionsStore', function(Restangular) {
return { return {
transactions: [], 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() { sum: function() {
var sum = 0; var sum = 0;
this.transactions.forEach(function(el) { this.transactions.forEach(function(el) {
Expand Down

0 comments on commit a0629f5

Please sign in to comment.