2016-08-08 24 views
1

私はイオンプロジェクトに取り組んでいます。私は、入力フィールドに「私のカスタムテキスト」を参照してください。ブラウザを開き、しかし、ときに私はそれを変更したとき、私はなぜ知らないが、ng-model correct.Iを動作しませんがtabsionic ng-modelが正しく動作しない

というデフォルトstarterで新しいプロジェクトを開始しましたコンソールでは、同じテキスト "私のカスタムテキスト"が表示されますが、それは自分の入力で変更する必要があります。したがって、変更は$scope.getUserNameに適用されません。私はデバッグしようとしたが$scopeの内部に$scopeを作成したことがわかりましたが、このようにアクセスしようとしたときにundefinedを得ました。

誰も私に何が起こっているのか、何が間違っているのか説明できますか?ここで

www/js/controllers.js

angular.module('starter.controllers', []) 

.controller('DashCtrl', function($scope) { 

    $scope.getUserName = 'my custom text'; 

    $scope.nameChange = function(){ 
     console.log($scope.getUserName); 
    }; 

}) 

.controller('ChatsCtrl', function($scope, Chats) { 
    // With the new view caching in Ionic, Controllers are only called 
    // when they are recreated or on app start, instead of every page change. 
    // To listen for when this page is active (for example, to refresh data), 
    // listen for the $ionicView.enter event: 
    // 
    //$scope.$on('$ionicView.enter', function(e) { 
    //}); 

    $scope.chats = Chats.all(); 
    $scope.remove = function(chat) { 
    Chats.remove(chat); 
    }; 
}) 

.controller('ChatDetailCtrl', function($scope, $stateParams, Chats) { 
    $scope.chat = Chats.get($stateParams.chatId); 
}) 

.controller('AccountCtrl', function($scope) { 
    $scope.settings = { 
    enableFriends: true 
    }; 
}); 

からのコードであり、これはちょっと問題がある場合、私はちょうど考え出しみんな私のwww/templates/tab-dash.html

<ion-view view-title="Dashboard"> 
    <ion-content class="padding"> 
    <h2>Welcome to Ionic</h2> 
    <input ng-model="getUserName" ng-change="nameChange()" name="anim" class="my-input" 
     aria-describedby="inputDescription" /> 
    <p> 
    This is the Ionic starter for tabs-based apps. For other starters and ready-made templates, check out the <a href="http://market.ionic.io/starters" target="_blank">Ionic Market</a>. 
    </p> 
    <p> 
     To edit the content of each tab, edit the corresponding template file in <code>www/templates/</code>. This template is <code>www/templates/tab-dash.html</code> 
    </p> 
    <p> 
    If you need help with your app, join the Ionic Community on the <a href="http://forum.ionicframework.com" target="_blank">Ionic Forum</a>. Make sure to <a href="http://twitter.com/ionicframework" target="_blank">follow us</a> on Twitter to get important updates and announcements for Ionic developers. 
    </p> 
    <p> 
     For help sending push notifications, join the <a href="https://apps.ionic.io/signup" target="_blank">Ionic Platform</a> and check out <a href="http://docs.ionic.io/docs/push-overview" target="_blank">Ionic Push</a>. We also have other services available. 
    </p> 
    </ion-content> 
</ion-view> 

答えて

0

です。

私はだから今、それが今ではすべてが、この記事をチェックアウト働く理由を理解するには、この

.controller('DashCtrl', function($scope) { 

    $scope.userObject = { 
     username: 'custom' 
    } 

    $scope.nameChange = function(){ 
     console.log($scope.userObject.username); 
    }; 

}) 

のように見えます/controllers.js

でNG-モデル=「userObject.username」と同じでng-model="getUserName"を置き換えます。

https://github.com/angular/angular.js/wiki/Understanding-Scopes

関連する問題