Reputation: 2175
Hi I am developing web application in Angularjs. I am finding hard to reload controller. I am using ui-routing. I have created plunker at //plnkr.co/edit/ozojBNobd44SqGeEVvvN?p=preview.
I have login tab. On clicking on login my login.html will be rendered. After user entering username and password when the user clicks on Login I want to reload the scotchController inside app.js file.
I tried many methods including $state.go() and transition. None of them worked out. May i get some help to fix this? Any help would be appreciated. Thank you.
Upvotes: 0
Views: 539
Reputation: 8166
Have you tried using this ?
<div ng-app="myApp" ng-controller="loginCtrl">
<button ng-click="doLogin();"></button>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('loginCtrl', function($scope, $rootScope) {
function doLogin($scope) {
// call service and call this on success
var arrayData = [1,2,3];
$rootScope.$emit('someEvent', arrayData);
}
});
app.controller('scotchController', function($scope, $rootScope,$state) {
$rootScope.$on('someEvent', function(event, data) {
console.log(data);
$state.go($state.current, {}, {reload: true});
});
});
</script>
Upvotes: 1