Below is my html code, I have a method in
moreThanOne.html
which makes variable
show
as true therefore it loads one.html for the first time and calls the init method of my controller. but whenever I change value of show again it does not reload the controller associated with one.html.
So my requirement here is init() method of initiatePaymentCtrl should get call whenever I click a button associated with another controller, so that data refreshes on one.html
<div data-ng-if="data.length>1">
<div data-ng-include="'moreThanOne.html'"></div>
</div>
<div data-ng-if="data.length==1">
<div data-ng-controller="initiatePaymentCtrl" data-ng-include="'one.html'"></div>
</div>
<div data-ng-if="show">
<div data-ng-controller="initiatePaymentCtrl" data-ng-include="'one.html'"></div>
</div>
Controller
app.controller('initiatePaymentCtrl', function($scope, $http, paymentService) {
function init() {
alert('init');
var issuerId = paymentService.getIssuerId();
var paymentItemId = paymentService.getPaymentItemId();
$scope.paymentOptions = {};
if (typeof issuerId !== "undefined") {
paymentService.getPaymentOptions(issuerId,paymentItemId).then(
function(paymentOptions) {
$scope.paymentOptions = paymentOptions;
});
}
}
init();
$scope.initiateInitialPayment = function(){
paymentService.initiateInitialPayment();
}
});
I cant use service as chances are there that data will not change on click
showwhich is primitive data type use object and property like$scope.object = { show : true }. Sometimes if you're using primitives it won't reflect in parent & child controllers as it's pass by value and not by reference