Issue
in app.js i'm using in callback function broadcast on the $rootScope to get fired method on the second controller.
function onSuccess(state) {
if (state != true) {
} else {
$rootScope.$broadcast('proximityCatched', null);
}
//console.log('Proximity state: ' + (state ? 'near' : 'far'));
};
On the controller i have listener:
$rootScope.$on('proximityCatched', function () {
alert("TEST");
});
Problem is that alert("TEST"); is triggered twice.
I tried to find any working solution using stopPropagation or using broadcasting on the normal scope, but without luck.
How can i do it please in the right way?
Thanks for any advice.
Edit: Router config:
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('game', {
url: "/game",
templateUrl: "templates/game.html",
controller: "GameCtrl"
})
.state('home', {
url: "/home",
templateUrl: "templates/home.html",
controller: "HomeCtrl"
})
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/home');
});
Solution
If you are attaching controller twice it will call twice.
check if you attaching controller in the routes
configs and the html (by using ng-controller
), if you attaching twice (using both ways) please remove one.
Answered By - Kalhan.Toress
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.