繁体   English   中英

离子angularjs中的$ scope值不会更新侧面菜单

[英]$scope value in ionic angularjs is not updates the side-menu

我在离子应用程序中遇到一个问题,该应用程序的侧面菜单带有namepicture ,并且是父级和abstract:true 在同一控制器中,有一个更新功能,它可以更新scope.picture ,但是侧面菜单画面不会被更新。

controller('AppCtrl', function($scope,$window,$rootScope,$location,$http,$state,$cordovaCamera,$ionicLoading,$q,login_Service) 
{               
    $scope.user_Name=$rootScope.u_name;            
    $scope.uid=$rootScope.user_id;
    $scope.pass=$rootScope.password;
    $scope.user_Picture=$rootScope.pic;
    $scope.whats=$rootScope.wh; 

    $scope.update_u=function(topic){      
        $scope.user_Picture=topic['picture']; 
        $scope.whats=topic['e_whats'];
    }                  
});

this is side-menu template 

<ion-side-menus>

  <ion-side-menu-content>
    <ion-nav-bar class="bar-light nav-title-slide-ios7">
      <ion-nav-back-button class="button-clear"><i class="icon ion-ios7-arrow-back"></i> Back</ion-nav-back-button>
    </ion-nav-bar>
    <ion-nav-view name="menuContent" animation="slide-left-right"></ion-nav-view>
  </ion-side-menu-content>
  <ion-side-menu side="left">

    <!-- Sidebar Content -->
    <ion-content class="gem-sidebar dark">
      <!-- Profile Box - Extends ionic's .row -->
      <div class="row gem-sidebar-profile-box">
        <!-- Profile Thumb -->
        <div class="col col-25">
          <img src="img/gemionic/no-photo.jpg" ng-if="!user_Picture" class="gem-profile-image" alt="">
           <img src="http://www.cssolutionshub.com/php/images/user_img/{{user_Picture}}" ng-if="user_Picture" class="gem-profile-image">
        </div> 
        <!-- End Profile Thumb -->

        <!-- Profile Name -->
        <div class="col col-50">



          <h6> <a menu-close href="#" ng-click="edit_prof()">Edit Profile</a></h6>
          <h5 ng-if="user_Name !== undefined">{{user_Name}}</h5>
          <h4>{{whats}}</h4>
        </div>
        <!-- End Profile Name <a -->

        <!-- Account Settings Icon -->
        <div class="col col-25 gem-text-center">
          <i class="gem-profile-settings-icon ion-volume-high"></i>
        </div>
        <!-- End Account Settings Icon -->

      </div>
      <!-- End Profile Box -->
      <!--<ion-list>        
        <ion-item class="item-ng-click" nav-clear menu-close ng-click="login()">Login</ion-item>
        <ion-item nav-clear menu-close href="#/app/feed">Feed</ion-item>
        <ion-item nav-clear menu-close href="#/app/start">Starter View</ion-item>


      </ion-list> -->
    </ion-content>
    <!-- End sidemenu content -->
  </ion-side-menu>
</ion-side-menus>

这是我的编辑模板,单击了更新功能

<!-- Title for header bar (refer to www/index.html) -->
<ion-view title="Edit Profile">
  <!-- ======================
  LEFT SIDE BUTTON
  ====================== -->
  <ion-nav-buttons side="left">
    <button menu-toggle="left" class="button button-icon icon ion-navicon"></button>
  </ion-nav-buttons>

  <!-- ======================
  RIGHT SIDE BUTTON
  ====================== -->
  <ion-nav-buttons side="right">
    <button class="button button-icon icon ion-checkmark-circled"></button>
  </ion-nav-buttons>


  <!-- ======================
  MAIN CONTENT SECTION
  ====================== -->
  <ion-content class="has-header gem-ion-content profile-edit">
    <!-- ======================
    GEMIONIC PROFILE ADD PICTURE BANNER
    ====================== -->
    <!-- <div class="gem-profile-media">
      <div class="gem-profile-details profile2">
        <div class="text-center">
          <i class="icon ion-plus-circled add-user-pic-icon"></i>
          <p class="uppercase">Add user pic</p>
        </div>
      </div>
    </div> -->
     <img ng-if="topic.picture !== undefined && img===undefined " ng-src="http://www.cssolutionshub.com/php/images/user_img/{{topic.picture}}" alt="" width="100%" height="20%" ng-click="addMedia()"> 

             <img ng-if="topic.picture === undefined && img===undefined" ng-src="img/gemionic/no-photo.jpg" width="100%" height="20%" ng-click="addMedia()"> 
              <img src="{{img}}" ng-if="img!==undefined" width="100%" height="20%" ng-click="addMedia()">
    <!-- ======================
    END GEMIONIC PROFILE ADD PICTURE BANNER
    ====================== -->

    <!-- Standard Ionic List -->
    <div class="list">

      <label class="item item-input item-stacked-label">
        <span class="input-label">What Now</span>
        <input type="text" ng-model="topic.whats">
      </label>    

      <label class="item item-input item-stacked-label">
        <span class="input-label">Password</span>
        <input type="password" ng-model="topic.password">
      </label>
    <button class="button button-full button-positive" ng-click='update_u(topic)'>
      Update
  </button>
  <button class="button button-full button-positive" ng-click='go_feed()'>
      Cancel
  </button>
</div>
  </ion-content>
</ion-view>

请尝试以下操作:

$scope.update_u=function(topic){
  $scope.whats = topic.whats;   
  $scope.user_Picture=topic['picture'];
}

您可以尝试一下(在AppCtrl内部)。 $ ionicView.beforeEnter函数中的代码将在每次调用该视图时执行:

$scope.$on('$ionicView.beforeEnter', function () {
      // Code you want executed every time view is opened
      $scope.update_u=function(topic){      
          $scope.user_Picture=topic['picture']; 
          $scope.whats=topic['e_whats'];
      }
}

这也可能是由于控制器的缓存。 您可以使用以下cache: false,在route.js上将其停止cache: false,行。 参见以下类似解决方案:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM