I've looked around and found the same question:
Self-references in object literal declarations
I tried the solution and it didn't work.
HTML:
<input type="number" placeholder="Bells" ng-model="ctrl.have">
<input type="number" placeholder="Bells" ng-model="ctrl.need">
<h3>{{ctrl.have}} bells</h3>
<h3>{{ctrl.need}} bells</h3>
<h1>You need:</h1>
<p id="diff">{{ctrl.diff = ctrl.need - ctrl.have}} bells</p>
<div ng-repeat="beetle in ctrl.beetles">
{{beetle.qty()}}
<img ng-src="{{beetle.image}}" width="100" height="100">
<p>{{beetle.creature}}</p>
<p class="price">{{beetle.price}}</p>
JS:
var ctrl = this;
ctrl.have = 0;
ctrl.need = 0;
ctrl.beetles = [{
image: 'cyclostag.jpg',
creature: 'Cyclommatus Stag',
price: '8000',
qty: function() {
this.amount = ctrl.need / this.price;
return this.amount;
}
}.qty(),...
When it's set like this, the information doesn't show at all. I'm trying make the qty property show as (ctrl.need - ctrl.have) / price of the creature. How do I fix this?