My issue: If i put an interger inside [] from the ng-repeat="n in []" line, it works, but what I want is to be able to use stock.price | BuySellAmount:ctrl.money which is a custom filter that basically divides the total amount of money a person has, by the amount the stock is worth. but when I just add stock.price | BuySellAmount:ctrl.money within the [] i get an error. So how can I achieve addding that information within the []
<div ng-if="stock.price | BuySellAmount:ctrl.money" class="input-group col-md-1">
<select class="form-control ">
<option ng-repeat="n in [] | makeRange" ng-selected= "{{n == stock.price | BuySellAmount:ctrl.money}}">{{n}}</option>
</select>
<span class="input-group-btn">
<button ng-if="stock.price | BuySellAmount:ctrl.money" class="btn btn-success" ng-click="buyStock()">Buy</button>
</span>
</div>
(function() {
'use strict';
angular
.module('MODULE')
// controller
.controller('CONTROLLER',['$http', function($http){
var self = this;
self.money = 50;
// get the json feed and create a new array with the prices and labels
$http.get('js/stocks.json')
.success(function(data, status, headers, config) {
//self.stockList = angular.copy(data.stocks);
//console.log(self.stockList);
var stocks = [];
for (var i = 0; i < data.stocks.length; i++) {
stocks.push({
name: data.stocks[i].name,
price: Math.floor(Math.random()*(600-data.stocks[i].price+1)+data.stocks[i].price)
});
}
self.stockList = stocks;
})
.error(function(data, status, headers, config) {
// log error
});
}])
.filter('randomPrice', function() {
return function(min, max)
{
var max = 5000;
console.log()
return Math.floor(Math.random()*(max-min+1)+min);
}
})
.filter('BuySellAmount', function() {
return function(stockprice,moneyinhand)
{
//Math.random()*(max-min+1)+min
var amount = Math.floor(moneyinhand/stockprice);
return amount;
}
})
.filter('makeRange', function() {
return function(input) {
var lowBound, highBound;
switch (input.length) {
case 1:
lowBound = 0;
highBound = parseInt(input[0]) - 1;
break;
case 2:
lowBound = parseInt(input[0]);
highBound = parseInt(input[1]);
break;
default:
return input;
}
var result = [];
for (var i = lowBound; i <= highBound; i++)
result.push(i);
return result;
};
}); // end
})();