I need to call method for initialization user setting values (which are set to rootscope) from second cotroller in method of the first controller.
After the values are succesfully set to rootscope return premise and continue in executing of the second method of the first controller.
I tried it with emit and broadcast examples, but without luck.
Could somebody please give me a advice how to do it correctly?
I am on Angular 1.2 and Ionic 1, beta 13
Many thanks for any help.
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();
});