I am facing a challenge where I need to initialize user setting values (which are set to rootscope) from the second controller's method in the first controller.
Once the values are successfully set to rootscope, I need to return a premise and continue executing the second method of the first controller.
I have tried using emit and broadcast examples, but haven't had any luck so far.
Can someone please provide advice on how to accomplish this correctly?
I'm working with Angular 1.2 and Ionic 1, beta 13
Thank you in advance for any assistance.
Template:
<ion-view title="{{ 'DAYS_RESULTS' | translate }}" >
<ion-content ng-controller="DailyStatsCtrl" ng-init="setData()">
Code:
// First cotroller call setData in ng-init
angular.module('starter')
// Controller definition
.controller('DailyStatsCtrl', function($scope, $rootScope, $ionicSlideBoxDelegate, $timeout , $ionicLoading , $q, $translate, DialsComputeService, cordova, LocalStorService, $ionicPopup, $state, $ionicNavBarDelegate, testService, $ionicPlatform) {
$scope.setData = function() {
$ionicPlatform.ready(function() {
$timeout(function() {
$scope.$emit("onSomething", "");
alert("TEST");
}, 1000);
});
};
In the second controller:
angular.module('starter')
// Controller definition
.controller('SettingsCtrl', function($scope, $rootScope, $ionicLoading, $ionicPlatform, LocalStorService, $timeout, $translate, $ionicPopup, $state, $ionicNavBarDelegate) {
$scope.getUserSettigns = function() {
alert("received");
$scope.test = 'event received';
}
$scope.$on('onSomething', function(e) {
$scope.getUserSettigns();
});