2013-07-23 4 views
3

컨트롤러가 두 번 실행되는 문제가 있습니다. 그러나 볼 수있는 복제본이 없습니다 (심지어 내 구성 파일을 통해 대소 문자 검색을 실행해도 경로 구성과 실제 컨트롤러에 하나만 표시됩니다).angularjs 컨트롤러가 2 번 실행합니다.

경로 설정 :

$routeProvider.when('/cb159e1ec61d0613f10ab397d8bd6782',{ 
    templateUrl: view+'passwordreset.html', 
    controller:'passwordreset' 
}); 

컨트롤러 :

App.controller('passwordreset',['$scope','$http', 
    function($scope,$http){ 
     $scope.token='asdf' 
     console.log($scope.token); // <-- logs 2x to console 
}]); 

passwordreset.html : 또한

<div class="row"> 
    <div class="small-12 columns"> 
     <fieldset class="content-box"> 
      password reset {{token}} 
     </fieldset> 
    </div> 
</div> 

, 나는 새로운 경로를 생성 시도했습니다, 여전히 두 번 기록합니다. 캐시도 지 웠습니다.

//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 for Home controller are created) 
}); 
+1

아마도 도움이됩니다 ... http : //stackoverflow.com/questions/15535336/combating-angularjs-executing-controller-twice – veritasetratio

+0

나는 내 컨트롤러가 두 번 호출되지 않았는지 확인했습니다. 나는 나의 파일 (1. 컨트롤러 자체, 2. 나의 루트 구성에서)을 통해 검색을 실행할 때 컨트롤러의 두 인스턴스 만 볼 수 있습니다. 다른 컨트롤러에서도 마찬가지입니다. angularjs-batarang 도구를 실행하면 두 개의 개별 범위가 컨트롤러에 대해 생성되었음을 나타냅니다. –

+0

ng-controller를 라우트 구성뿐만 아니라 내 뷰에 추가하면 범위가 4 번 복제됩니다. 예 : Scope00G

답변

8

내가 문제를 알아 냈어 : 일부 컨트롤러는

또 다른 예를 (일부는 일부 두 번, 한 번 보여, 나는 몇 컨트롤러에 경고를 넣어) 일부는 두 번, 한 번 실행합니다. 사용자가 ng-show="user.authorized"ng-show="!user.authorized"을 사용하여 권한이 부여되었는지 여부에 따라 두 가지 레이아웃이있었습니다. 각각은 <div ng-view>입니다. ng-viewng-show이 true인지 false인지 처리됩니다.

ng-show의 모든 내용이 사실인지 아닌지를 알지 못했습니다.

수정 : ng-show 대신 ng-switch을 사용합니다. 이렇게하면 조건이 충족 될 때까지 뷰가 처리되지 않습니다.

+0

[breadcrumbs] (http://stackoverflow.com/a/29240618/435460)를 내 미래 단계로 다시 돌리십시오. – JesseBuesking

관련 문제