I am getting the value inside {{total}} but when i am initializing this value in ng-init , not getting the value of total in ng-init
For example :
Calling this function when calculating total price:
ng-change HTML part:
<div class="col-md-2 col-sm-2 col-lg-2 col-lg-offset-1 col-xs-12 ">
<select class="form-control select-data pull-right mt10" ng-model="book.package[$index]" ng-change="get_total_price(x.price,book.package[$index],x.id)">
<option value="">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>
</div>
ng-change="get_total_price(x.price,book.package[$index],x.id);
From this i am getting the total price
${{total}}
Now i want to initialise this through ng-init like this
<input type="text" class="hidden" placeholder="Enter name" ng-init="book.total_price= total" ng-model="book.total_price">
but when i checked this through json like this
{{total_price | json}}
it's display the total_price 0 instead of which i'm getting in {{total}}
Can anyone help me to get this? Any help will be appreciated.
Thanks in advance.
Edited :
$scope.get_total_price = function ($price,$value,$id) {
$scope.total = $scope.total + Number($price)*Number($value);
};
This is the function by which i'm getting price value and returning to this my view and this return price i need to show initialized in ng-init.
ng-initwarns against; this is adding unnecessary logic. You should always initialize your properties in your controller, not in your HTML. if you really feel like usingng-initis a necessity, you should try to provide a minimal reproducible example demonstrating why.