angularjs控制器执行2次控制器、angularjs

由网友(听书人)分享简介:我有凡控制器执行两次有问题,但我没有重复的,我可以看到(甚至贯穿我的文件的区分大小写的搜索只显示之一,路由配置和我的实际控制人)。路由配置: $ routeProvider.when('/ cb159e1ec61d0613f10ab397d8bd6782',{    templateUrl:鉴于+'passwordr...

我有凡控制器执行两次有问题,但我没有重复的,我可以看到(甚至贯穿我的文件的区分大小写的搜索只显示之一,路由配置和我的实际控制人)。

路由配置:

  $ routeProvider.when('/ cb159e1ec61d0613f10ab397d8bd6782',{    templateUrl:鉴于+'passwordreset.html',    控制器:'p​​asswordreset}); 

控制器:

  App.controller('passwordreset',['$范围,$ HTTP,    功能($范围,$ HTTP){        $ scope.token =ASDF        的console.log($ scope.token); //<  - 原木2倍安慰}]); 

passwordreset.html

 < D​​IV CLASS =行>    < D​​IV CLASS =小12列>        <字段集类=内容框>            密码重置{{令牌}}        < /字段集>    < / DIV>< / DIV> 
值得HTML5开发者收藏的10大移动APP开发框架

另外,我创建了一个新的途径,并试图,还记录了两次。我已经清除我的缓存。有些控制器执行一次,有的两次(我把警报在几个控制器,部分显示一次,有的两次)

另外一个例子:

  //航线配置    $ routeProvider.when('/',{     templateUrl:鉴于+'家',     控制器:家    });//模板        < D​​IV NG控制器=测试>将< / DIV>//控制器Lmu.controller('家',函数($范围){    $ scope.home ='家';    警报($ scope.home); <  - 警报2X(创建了Home控制器两个作用域)}); 

解决方案

我想通了这个问题。我这取决于用户是否使用NG-秀=user.authorized和NG-秀=!user.authorized授权有两个布局。每过一个。每次NG-观点得到处理NG-节目是否是真还是假。

我不知道一切都在NG-表演得到处理是否属实。

修复:使用纳克开关代替NG-表演。这样下去不被处理,直到满足条件的看法。

I have a problem where a controller executes twice, yet I do not have duplicates that i can see (even running a case sensiTIve search through my files only shows one in route configuration and my 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 to 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 a new route and tried, still logs twice. I've cleared my cache as well. Some controllers execute once, some twice (I put an alert in a few controllers, some show once, some 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 for Home controller are created)
});

解决方案

i figured out the problem. I had two layouts depending on whether the user was authorized using ng-show="user.authorized" and ng-show="!user.authorized". each had a . every ng-view gets processed whether ng-show is true or false.

i didn't realize everything in ng-show gets processed whether true or not.

Fix: used ng-switch instead of ng-show. this keeps the view from being processed until the condition is met.

阅读全文

相关推荐

最新文章