【发布时间】:2017-02-12 20:17:46
【问题描述】:
所以我正在使用 ionic 来构建一个混合应用程序。需要明确的是,这与 android 完美配合!
这是我的登录 html:
<body ng-app="starter">
<head>
<script src="phonegap.js"></script>
</head>
<ion-header-bar align-title="center" class="bar-positive" ng-controller="BackBtnCtrl">
<button class="button" ng-click="goBack()"><<</button>
<h1 class="title">Push Notifications</h1>
</ion-header-bar>
<ion-content>
<div class="list">
<form style="display: block; margin: 100px">
<label class="item item-input">
<input type="text" ng-model="name" placeholder="Name">
</label>
<label class="item item-input">
<input type="password" ng-model="password" placeholder="Password" style="text-align: center">
</label>
<label class="item item-input">
<input type="email" ng-model="email" placeholder="Email" style="text-align: center">
</label>
<label class="item item-input">
<input type="text" ng-model="company" placeholder="Company Name" style="text-align: center">
</label>
<button class="button button-block button-positive" type="submit" ng-click="doLogin()">Register</button>
</form>
</div>
</ion-content>
</body>
现在在我的app.js 中,我将离子含量的控制器声明为:
.state('login', {
url: '/login',
templateUrl: 'templates/login.html',
controller: 'LoginCtrl'
})
当我在 android 应用程序中访问 $scope.email 时,它会正确返回。但是当我在 iOS 应用程序中访问 $scope.email 时,我得到了未定义。有人听说过这个问题吗?
控制者:
.controller('LoginCtrl', function($scope, $rootScope, $http, $state, $ionicPlatform) {
if(window.localStorage.getItem("loggedIn") == undefined || window.localStorage.getItem("loggedIn") == null) {
// This function only gets called when the register button gets hit. It posts to the server to store the users registration data
$scope.doLogin = function() {
if ($scope.name == undefined || $scope.password == undefined|| $scope.email == undefined|| $scope.company == undefined) {
window.plugins.toast.showWithOptions(
{
message: 'Please Fill in ALL Fields',
duration: 'long',
position: 'middle'
});
alert($scope.email);
alert("returning");
return;
}
alert($scope.email);
【问题讨论】:
-
那是什么规则? $scope.email 应该是用户在应用程序运行时输入的文本。
-
我误读了代码,因为函数没有关闭,而且格式很差。至于点看这个3分钟视频youtube.com/watch?v=DTx23w4z6Kc
-
我只是从文本编辑器复制粘贴到这里的代码插入处。很抱歉格式冒犯了您。你知道为什么在 iOS 上 $scope.email 是未定义的,即使文本在字段中?
-
您什么时候在应用中打印“$scope.email”?
-
当注册按钮被按下时,它会调用 doLogin() 函数。然后它 alert($scope.email) 应该是用户输入的文本。但它在 iOS 应用上显示未定义。
标签: javascript html ios angularjs