2017-05-26 2 views
0

Ionic Frameworkを使用してハイブリッドアプリケーションを開発しています。しかし、私のアプリケーションは、ユーザーがハイブリッドアプリケーションに戻ったときに二重バインドに失敗しました。アプリケーションはlocalstorageからArrayオブジェクトを取得できましたが、ngrepeatsはlocalstorageから割り当てられたvarをロードできませんでした。以下は私のコードです。Ionic Cordova:Angualarjs二重結合が機能しない

controller.js

.controller('ChatsCtrl', ['$scope','$state', '$ionicTabsDelegate' , '$ionicListDelegate', '$rootScope' 
    ,function($scope,$state,$ionicTabsDelegate, $ionicListDelegate, $rootScope) { 

     var channel_list = []; 
     channel_list = localStorage.getItem("channel_list"); 
     $scope.chats = channel_list; 
}]) 

HTMLファイル

<ion-view cache-view="false" view-title="DRDM Chat"> 
    <div class="bar bar-header bar-calm"> 
      <div class="h1 title">DRDM Chat</div> 
    </div> 
    <ion-content on-swipe-right="goBack()" on-swipe-left="goForward()"> 
     <br><br> 
     <ion-list> 
      <ion-item class="item-remove-animate item-avatar item-icon-right" ng-repeat="chat in chats" type="item-text-wrap" ng-click="chatRoom({{'chat.displayName'}}, {{'chat.channelID'}})"> 
       <img ng-src="data:image/png;base64,{{chat.profilePicture}}"> 
       <h2>{{chat.displayName}}</h2> 
       <p>{{chat.lastText}}</p> 
       <i class="icon ion-chevron-right icon-accessory"></i> 
       <ion-option-button class="button-assertive" ng-click="remove($index, chat.channelID)">Delete</ion-option-button> 
      </ion-item> 
     </ion-list> 
    </ion-content> 
</ion-view> 

答えて

0

はあなたのリストを初期化し、このような何かを再ページロードの関数を呼び出してみ、

Controller.js

$scope.init = function(){  
    var channel_list = []; 
     channel_list = localStorage.getItem("channel_list"); 
     $scope.chats = JSON.parse(channel_list); 
    } 
    $scope.init(); 

そして、あなたがこのページを訪問し、これまでこの機能が起動されたときに確認してください。 注:同じページにあり、リストを再バインドする場合は、必要に応じてgoBack()またはgoForward()関数でこの関数を呼び出します。

これがあなたの問題を解決することを願っています。

+0

それは私のために働きます –

+0

@ChanYoongHon素晴らしいです。 – DevSab

0

JS

var channel_list = []; 
    channel_list = localStorage.getItem("channel_list"); 
    $scope.chats = JSON.parse(channel_list); 

HTMLファイル

<ion-view cache-view="false" view-title="DRDM Chat"> 
<div class="bar bar-header bar-calm"> 
     <div class="h1 title">DRDM Chat</div> 
</div> 
<ion-content on-swipe-right="goBack()" on-swipe-left="goForward()"> 
    <br><br> 
    <ion-list> 
     <ion-item class="item-remove-animate item-avatar item-icon-right" ng-repeat="chat in chats" type="item-text-wrap" ng-click="chatRoom(chat.displayName,chat.channelID)"> 
      <img ng-src="data:image/png;base64,{{chat.profilePicture}}"> 
      <h2>{{chat.displayName}}</h2> 
      <p>{{chat.lastText}}</p> 
      <i class="icon ion-chevron-right icon-accessory"></i> 
      <ion-option-button class="button-assertive" ng-click="remove($index, chat.channelID)">Delete</ion-option-button> 
     </ion-item> 
    </ion-list> 
</ion-content> 

ng-click="chatRoom(chat.displayName,chat.channelID)このような値を渡します。

+0

まだ同じ問題があります –

関連する問題