Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/472.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AngularJs$范围在ionic项目中未定义_Javascript_Angularjs_Ionic Framework - Fatal编程技术网

Javascript AngularJs$范围在ionic项目中未定义

Javascript AngularJs$范围在ionic项目中未定义,javascript,angularjs,ionic-framework,Javascript,Angularjs,Ionic Framework,我正在和爱奥尼亚公司做一个项目 这是我的简单控制器: var app = angular.module('myApp', ['ionic']); app.controller("loginController", ['$scope', function($scope){ $scope.userName = "" $scope.password = "" $scope.login = function(){ //some login things her

我正在和爱奥尼亚公司做一个项目

这是我的简单控制器:

var app = angular.module('myApp', ['ionic']);

app.controller("loginController", ['$scope', function($scope){
    $scope.userName = ""
    $scope.password = ""

    $scope.login = function(){
        //some login things here
    };
}]);
我的HTML

 <ion-content ng-controller="loginController">
            <form class="list" ng-submit="login()">
              <label class="item item-input">
              <span class="input-label">Username</span>
              <input type="text" ng-bind="userName">
              </label>
              <label class="item item-input">
              <span class="input-label">Password</span>
              <input type="password" ng-bind="password">
            </label>
            <button class="button button-block button-positive">
              Login
            </button>
          </form>
</ion-content>

用户名
密码
登录

当我点击登录按钮时,
login
功能正在运行,但我无法访问
userName
password
变量,因为同时
$scope
未定义

您需要在输入字段上放置
ngModel
指令,而不是
ngBind

<input type="text" ng-model="userName">

完整的HTML代码将变成:

<form class="list" ng-submit="login()">
    <label class="item item-input"> 
        <span class="input-label">Username</span>
        <input type="text" ng-model="userName">
    </label>
    <label class="item item-input"> 
        <span class="input-label">Password</span>
        <input type="password" ng-model="password">
    </label>
    <button class="button button-block button-positive">Login</button>
</form>

用户名
密码
登录

这很有效。如果可能的话,我会把这个标记为答案。谢谢