2017-03-16 3 views
-1

Ich bin neu in Angular JS und versuche, den Benutzernamen und E-Mail auf der Browser-Konsole zu drucken. Ich bekomme entweder 'undefiniert' oder es druckt die Zeichenfolge, die ich angegeben habe. Wie kann ich die Ausgabe als E-Mail und Benutzername erhalten, die der Benutzer eingibt? Hier ist mein Code:console.log() nicht die Ausgabe

profile.html

<ion-view title="Profile" id="page2"> 
<ion-content padding="true" class="has-header"> 
    <div ng-controller="profileCtrl"></div> 
    <div id="profile-form1" class="list"> 
    <label class="item item-input"> 
    <input type="text" placeholder="Email" ng-model="Email"> 
    </label> 
    <label class="item item-input"> 
    <input type="text" placeholder="Username" ng-model="Username"> 
    </label> 
    <label class="item item-input" > 
    <input type="password" placeholder="Password" ng-model="Password"> 
    </label> 
    <ion-toggle toggle-class="toggle-balanced" id="profile-toggle1" ng-model="tc">Terms &amp; Conditions</ion-toggle> 
</div> 
<div ng-disabled=" (Email && Username && Password && tc) ? flase : true" ng-click="saveList()" style="border-radius:10px 10px 10px 10px;" class="button button-balanced button-block">Login</div> 
</ion-content> 
</ion-view> 

controller.js

.controller('profileCtrl', ['$scope', '$stateParams', 
    function ($scope, $stateParams) { 
    $scope.saveList = function(){ 
     console.log($scope.Email, $scope.Username); 
    } 
}]) 

Konsolenausgabe ist nur undefined undefined.

Vielen Dank.

+1

Nicht sicher, ob es um das Thema verwandt ist, aber Sie haben einen Tippfehler: 'ng -disabled = "(E-Mail && Benutzername && Passwort && tc)? flase: true" 'fase ist kein gültiger boolescher Wert. – Shilly

+1

'

' weil diese Schaltfläche _oder irgendetwas anderes_ nicht in Ihrem Controller ist – George

+0

@Shilly, wenn ich 'false' nicht einschließe, wird der Login-Button aktiviert, auch wenn keines der Felder gefüllt ist. Ich denke, es gibt keine andere Möglichkeit, die Login-Schaltfläche zu deaktivieren, wenn Felder leer sind. – Murali

Antwort

0

nicht schließen die div: <div ng-controller="profileCtrl"></div>

und nicht zu vergessen die div Tag zu schließen:

<ion-view title="Profile" id="page2"> 
<ion-content padding="true" class="has-header"> 
    <div ng-controller="profileCtrl"> <!-- open it here --> 
     <div id="profile-form1" class="list"> 
     <label class="item item-input"> 
      <input type="text" placeholder="Email" ng-model="Email"> 
     </label> 
     <label class="item item-input"> 
      <input type="text" placeholder="Username" ng-model="Username"> 
     </label> 
     <label class="item item-input" > 
      <input type="password" placeholder="Password" ng-model="Password"> 
     </label> 
     <ion-toggle toggle-class="toggle-balanced" id="profile-toggle1" ng-model="tc">Terms &amp; Conditions</ion-toggle> 
     </div> 
     <div ng-disabled=" (Email && Username && Password && tc) ? flase : true" ng-click="saveList()" style="border-radius:10px 10px 10px 10px;" class="button button-balanced button-block">Login</div> 
    </div> <!-- close it here --> 
</ion-content> 
</ion-view> 
Verwandte Themen