Created
April 23, 2015 12:49
-
-
Save aaronlelevier/90da27ca7336c775dc1d to your computer and use it in GitHub Desktop.
AngularJS Controller Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| define([ | |
| './module' | |
| ], function(module) { | |
| 'use strict'; | |
| module.controller('NewsletterCtrl', ['$scope', function($scope) { | |
| $scope.dj_test = "`test`: angular is loaded"; | |
| }]); | |
| module.controller('PricingCtrl', ['$scope', 'Pricing', function($scope, Pricing) { | |
| //prices will be from a DRF REST endpoint, so when changed in the DB, | |
| //they are auto-reflected here | |
| $scope.prices = Pricing.query(); | |
| $scope.volumes = [500, 2500, 5000, 7500]; | |
| $scope.volume = ""; | |
| $scope.submit_volume = function(volume) { | |
| $scope.volume = volume; | |
| } | |
| // calculate SMS cost | |
| $scope.calc_cost = function() { | |
| $scope.cost = 0; | |
| angular.forEach($scope.prices, function(p) { | |
| if ($scope.volume >= p.end) { | |
| $scope.cost += p.price * (p.end - p.start + 1); | |
| } else if ($scope.volume >= p.start && $scope.volume < p.end) { | |
| $scope.cost += p.price * ($scope.volume - p.start + 1); | |
| } | |
| }); | |
| return $scope.cost; | |
| } | |
| $scope.$watch( | |
| 'volume', | |
| function(newValue) { | |
| return newValue; | |
| }); | |
| }]); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment