I'm having a problem sharing data between controllers, I used a service, seems working but something doesn't work as it should.
My problem is: When I click a row (in the ng-repeat part), it fires correctly service function (ui_mgmt), but it doesn't update ui_controller(controller) $scope.show_details var!
JS Code
ui_service_f = function() {
//Service which should update Controller 1 var
this.show_details = "-1";
this.ui_mgmt = function(det,data) {
this.show_details = 1;
};
};
ui_controller =function($scope,ui_service) {
//Controller1
//I think this part is bugged
$scope.show_details = ui_service.show_details;
$scope.sub_bottom_menu = ui_service.sub_bottom_menu;
};
sim_list_placer =function($scope,service_sim,ui_service) {
//Controller2
$scope.ui_mgmt = function(a,b) {
ui_service.ui_mgmt(a,b);
};
};
HTML
<div ng-controller="sim_list_placer">
<button ng-click="reload_sim_list()">Reload</button>
<table class="td_mc_table">
<thead>
<td>pk</td><td>ICCID</td><td>Operatore</td>
<td>Numero Dati</td><td>PIN</td><td>PUK</td>
<td>Contratto</td><td>Costo</td><td>APN</td><td>Attivazione</td>
</thead>
<tbody>
<tr ng-repeat="sim in sim_list" ng-click="ui_mgmt(1,sim)">
<td>{{ sim.pk }}</td>
<td>{{ sim.sim_iccid }}</td>
<td>{{ sim.sim_operatore }}</td>
<td>{{ sim.sim_ndati }}</td>
<td>{{ sim.sim_pin }}</td>
<td>{{ sim.sim_puk }}</td>
<td>{{ sim.sim_contratto }}</td>
<td>{{ sim.sim_costo }}</td>
<td>{{ sim.sim_apn }}</td>
<td>{{ sim.sim_data_attivazione }}</td>
</tr>
</tbody>
</table>
</div>
<div ng-controller="ui_controller">
{{show_details}}
<div ng-if="show_details==1" class="td_mc_rightbar" >
Dettagli...
<div ng-switch="sub_bottom_menu">
<div ng-switch-when="sim_mgmt">
Blablablabla
</div>
</div>
</div>
</div>
I'm I missing something or....???
Thank you in advice :)
Andrea
$scope.someVar = service.getVar(). Also, as you do an implicit update of the data of another scope, I think you might need to do$scope.digest()