2016-08-08 17 views
1

Ich arbeite an ionischen Projekt. Ich weiß nicht, warum, aber ng-model tun correct.I nicht funktionieren haben neues Projekt mit Standard starter genannt tabsionische ng-Modell funktioniert nicht korrekt

gestartet Wenn ich den Browser öffne ich „meinen benutzerdefinierten Text“ in das Eingabefeld ein, aber wenn ich es ändern , in der Konsole sehe ich den gleichen Text "mein benutzerdefinierter Text", aber es sollte mit meiner Eingabe geändert werden. Änderungen gelten nicht für $scope.getUserName. Ich versuchte zu debuggen und stellte fest, dass es $scope in der $scope der DashCtrl eigenen eigenen schafft, aber als ich versuchte, Zugang zu ihm so zu erhalten $scope.child, ich bekam undefined.

Kann mir jemand erklären, was los ist und was mache ich falsch? Hier

ist der Code von 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 
    }; 
}); 

Und das ist mein 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> 

Antwort

0

Hey Jungs, die ich gerade herausgefunden, wo das Problem ist.

I ersetzt ng-model="getUserName" mit ng-Modell = "userObject.username" und gleicht in den /controllers.js

So, jetzt sieht es aus wie diese

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

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

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

}) 

warum funktioniert jetzt alles verstehen diesen Artikel überprüfen.

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