console.log()不打印输出

时间:2017-03-16 15:13:31

标签: javascript angularjs ionic-framework

我是Angular JS的新手,并尝试在浏览器控制台上打印用户名和电子邮件。我要么得到了未定义的'或者它打印我给的字符串。如何将输出作为用户输入的电子邮件和用户名获取?这是我的代码:

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);
    }
}])

控制台输出未定义未定义。

谢谢。

1 个答案:

答案 0 :(得分:0)

请勿关闭div:<div ng-controller="profileCtrl"></div>

并且不要忘记关闭div标记:

 <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>