javascript - angularjs controller executes 2 times -
i have problem controller executes twice, yet not have duplicates can see (even running case sensitive search through files shows 1 in route configuration , actual controller).
route config:
$routeprovider.when('/cb159e1ec61d0613f10ab397d8bd6782',{ templateurl: view+'passwordreset.html', controller:'passwordreset' });
controller:
app.controller('passwordreset',['$scope','$http', function($scope,$http){ $scope.token='asdf' console.log($scope.token); // <-- logs 2x console }]);
passwordreset.html
:
<div class="row"> <div class="small-12 columns"> <fieldset class="content-box"> password reset {{token}} </fieldset> </div> </div>
also, i've created new route , tried, still logs twice. i've cleared cache well. controllers execute once, twice (i put alert in few controllers, show once, twice)
another example:
//route config $routeprovider.when('/', { templateurl: view+'home', controller:'home' }); //template <div ng-controller="testing">a</div> //controller lmu.controller('home',function($scope){ $scope.home='home'; alert($scope.home); <-- alerts 2x (two scopes home controller created) });
i figured out problem. had 2 layouts depending on whether user authorized using ng-show="user.authorized" , ng-show="!user.authorized". each had . every ng-view gets processed whether ng-show true or false.
i didn't realize in ng-show gets processed whether true or not.
fix: used ng-switch instead of ng-show. keeps view being processed until condition met.
Comments
Post a Comment