2016-08-08 7 views
1

私が今直面している問題は、JSON.parse(localStorage.getItem('user_info'))); の後にどのようにこの文字列を$scopeオブジェクトに入れることができますか?Ionic framework、Angular Js

私の問題のために何か提案してください。あなたはAngularJS controllerを定義し、ng-controllerディレクティブを使用してイオン性のビューにバインドする必要があります事前

+0

http://stackoverflow.com/questions/35419566/updating-a-single-item-in-angular-scope-を参照してください。オブジェクト? –

答えて

0

感謝。以下はその例です— play.ionic.ioで遊んでみることをお勧めします。

JS

angular.module('app', ['ionic']).controller('MyController', function($scope) { 

    // localStorage.setItem('user_info', JSON.stringify('Hello World')); 
    $scope.userInfo = JSON.parse(localStorage.getItem('user_info')); 

}); 

HTML

<!DOCTYPE html> 
<html> 
    <head> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"> 
    <link href="https://code.ionicframework.com/1.0.0/css/ionic.min.css" rel="stylesheet"> 
    <script src="https://code.ionicframework.com/1.0.0/js/ionic.bundle.js"></script> 
    </head> 
    <body ng-app="app"> 
    <ion-pane> 
     <ion-header-bar class="bar-stable"> 
     <h1 class="title">LocalStorage Example</h1> 
     </ion-header-bar> 
     <ion-content class="padding" ng-controller="MyController"> 
     <h1>{{userInfo}}</h1> 
     </ion-content> 
    </ion-pane> 
    </body> 
</html> 
+0

偉大なブローはあなたに感謝します。 。ライトビート –

関連する問題