我正在建立一个离子项目。
这是我的简单控制器:
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
未定义
答案 0 :(得分:2)
您需要在输入字段而不是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>