Javascript 返回时不调用控制器

Javascript 返回时不调用控制器,javascript,angularjs,pug,Javascript,Angularjs,Pug,我正在使用angularJS和Jade进行开发。我让AppController贴在我的身体标签上。每次我访问新页面时,都会调用控制器。目前,我有两种不同的布局。一个有页眉、导航和页脚。另一个是侧边栏。当我访问第一个布局和第二个布局时,AppController调用。但是当我从第二个布局返回到第一个布局时。未调用AppController index.jade extends layout/layout block content html head // some metas and l

我正在使用angularJS和Jade进行开发。我让AppController贴在我的身体标签上。每次我访问新页面时,都会调用控制器。目前,我有两种不同的布局。一个有页眉、导航和页脚。另一个是侧边栏。当我访问第一个布局和第二个布局时,AppController调用。但是当我从第二个布局返回到第一个布局时。未调用AppController

index.jade

extends layout/layout
block content
html
 head
  // some metas and links
 body(ng-app="myApp", ng-controller="AppController")
  div(ng-show="!profile")
   include header
   include sidemenu
   include mainmenu

  div(ng-show="profile", id="Profile", style="display:none;")
   include profile/sidemenu

  div(ng-cloak, ng-view)
     block content

  div(ng-show="!profile")
   include footer

  div(ng-show="profile", id="Profile", style="display:none")
    include profile/scripts
布局。jade

extends layout/layout
block content
html
 head
  // some metas and links
 body(ng-app="myApp", ng-controller="AppController")
  div(ng-show="!profile")
   include header
   include sidemenu
   include mainmenu

  div(ng-show="profile", id="Profile", style="display:none;")
   include profile/sidemenu

  div(ng-cloak, ng-view)
     block content

  div(ng-show="!profile")
   include footer

  div(ng-show="profile", id="Profile", style="display:none")
    include profile/scripts
AppController

// When navigating to /profile it will call the second layout
// Otherwise first layout.

if($location.path().split('/')[1] == "profile") {
    angular.element('#Profile').css('display','block');
    $scope.profile = true;
}else{
    angular.element('#Profile').css('display','none');
    $scope.profile = false;
}
问题

当我从第二个布局导航回第一个布局时。侧栏(第二个布局)与第一个布局重叠。原因是没有调用AppController,因此没有调用css显示


我认为最好的方法是将控制器代码包装在函数周围,并使用
nginit
指令从两个层调用该函数

$scope.cssFunc = function(){

    if($location.path().split('/')[1] == "profile") {
        angular.element('#Profile').css('display','block');
        $scope.profile = true;
    }else{
        angular.element('#Profile').css('display','none');
        $scope.profile = false;
    }

}

发布第二个布局