I am new to angular js and just want to know how to reset scope of one controller from other controller.
I am having four different divs(controllers) having refresh button and in one main parent divs controller having dropdown selection.
-- with click on refresh button, dropdown change event works but if i click on refresh of particular divs then that div only not getting refresh on change event of dropdown.
var parentModule = angular.module("parentModule", []);
parentModule.factory('myService', function($http) {
return {
getDataForBox1:
function()
{
var box1data = $http.get('/testurl/test/getAllProfilesForBox1').then(function(result) {return result.data;});return box1data;
},
getDataForBox2:
function()
{
console.log("getDataForBox2 called")
var box2data = $http.get('/testurl/test/getAllProfilesForBox2').then(function(result) {return result.data;});return box2data;
},
getDataForBox3:
function()
{
console.log("getDataForBox3 called")
var box3data = $http.get('/testurl/test/getAllProfilesForBox3').then(function(result) {return result.data;});return box3data;
},
getDataForBox4:
function()
{
console.log("getDataForBox4 called")
var box4data = $http.get('/testurl/test/getAllProfilesForBox4').then(function(result) {return result.data;});return box4data;
}
}
});
parentModule.controller('box1Controller', function($scope, myService) {
$scope.go = function() {
myService.getDataForBox1().then(function(profiles1) {
.profiles1 = profiles1;
});
}
});
parentModule.controller('box2Controller', function($scope, myService) {
$scope.go2 = function() {
myService.getDataForBox2().then(function(profiles2) {
$scope.profiles2 = profiles2;
});
}
});
parentModule.controller('box3Controller', function($scope, myService) {
$scope.go3 = function() {
myService.getDataForBox3().then(function(profiles3) {
$scope.profiles3 = profiles3;
});
}
});
parentModule.controller('box4Controller', function($scope, myService) {
$scope.go4 = function() {
myService.getDataForBox4().then(function(profiles4) {
$scope.profiles4 = profiles4;
});
}
});
parentModule.controller('ctrl', function($scope, myService) {
$scope.changedValue = function() {
myService.getDataForBox1().then(function(profiles1) {
$scope.profiles1 = profiles1;
});
myService.getDataForBox1().then(function(profiles2) {
$scope.profiles2 = profiles2;
});
taForBox1().then(function(profiles3) {
$scope.profiles3 = profiles3;
});
myService.getDataForBox1().then(function(profiles4) {
$scope.profiles4 = profiles4;
});
};
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="parentModule">
<div style="width: 100%; display: table;" ng-controller="ctrl">
<div style="display: table-row">
<div style="display: table-cell; background-color: lightgreen"
ng-controller="box1Controller">
<b>Box - 1 </b>
<table class="table">
<tr ng-repeat="profile in profiles1">
<td>{{profile.firstname}}</td>
<!-- <td>{{profile.lastname}}</td> -->
<td> Server Date {{profile.serverDate}}</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
</table>
<a ng-click='go()'>Refresh</a>
</div>
<div style="display: table-cell; background-color: lightblue"
ng-controller="box2Controller">
<b>Box - 2</b>
<table class="table">
<tr ng-repeat="profile in profiles2">
<td>{{profile.firstname}}</td>
</tr>
</table>
<a ng-click='go2()'>Refresh</a>
</div>
<div style="display: table-cell; background-color: lightgreen"
ng-controller="box3Controller">
<b>Box - 3 </b>
<table class="table">
<tr ng-repeat="profile in profiles3">
<td>{{profile.firstname}}</td>
<!-- <td>{{profile.lastname}}</td> -->
<td>Server Date {{profile.serverDate}}</td>
</tr>
</table>
<a ng-click='go3()'>Refresh</a>
</div>
<div style="display: table-cell; background-color: lightblue"
ng-controller="box4Controller">
<b>Box - 4</b>
<table class="table">
<tr ng-repeat="profile in profiles4">
<td>{{profile.firstname}}</td>
<!-- <td>{{profile.lastname}}</td> -->
<td>Server Date {{profile.serverDate}}</td>
</tr>
</table>
<a ng-click='go4()'>Refresh</a>
</div>
<br> <br>
</div>
<div align="center">
<b>Refresh All Box :</b> <select ng-model="item" ng-change="changedValue()">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</div>
</div>
</div>
note : here i am making ajax call on refresh and drop down change event.
Have a snapshot of UI
I think there is problem of nested controller where parent controller is not having access to reset child controller scope.
