Javascript 无法读取属性';用户名';在angularjs中未定义的
我想用angularjs和ionic登录。但是当我运行这个程序时,这个程序是错误的。错误是: TypeError:无法读取未定义的属性“username” 有人帮我吗 表格:Javascript 无法读取属性';用户名';在angularjs中未定义的,javascript,angularjs,ionic-framework,Javascript,Angularjs,Ionic Framework,我想用angularjs和ionic登录。但是当我运行这个程序时,这个程序是错误的。错误是: TypeError:无法读取未定义的属性“username” 有人帮我吗 表格: <body ng-app="apps" ng-controller="PostController as postCtrl"> <ion-view view-title="Please Sign in"> <ion-content class="padding"> &
<body ng-app="apps" ng-controller="PostController as postCtrl">
<ion-view view-title="Please Sign in">
<ion-content class="padding">
<div class="list">
<label class="item item-input">
<input type="text" placeholder="Name" ng-model="postCtrl.inputData.username">
</label>
<label class="item item-input">
<input type="password" placeholder="Password" ng-model="postCtrl.inputData.password">
</label>
</div>
<div class="alert alert-danger" role="alert" ng-show="errorMsg">{{errorMsg}}</div>
<button class="button button-full button-balanced" ng-click="postForm()">Sign In</button>
</ion-content>
</ion-view>
<script src="controller.js"></script>
</body>
在你的控制器里做什么
var self = this;
self.inputData = {};
并替换this.inputData.username
与self.inputData.username
this.inputData.password
与控制器中的self.inputData.password
一起执行
var self = this;
self.inputData = {};
并替换this.inputData.username
与self.inputData.username
this.inputData.password
与self.inputData.password
我尝试了一个示例。看看这个
$scope.inputData = {
username: null,
password: null
}
我试了一个样品。看看这个
$scope.inputData = {
username: null,
password: null
}
你可以用角度来做,如下所示。。这应该是使用ng模型的正确目的 表格:
<body ng-app="apps" ng-controller="PostController as postCtrl">
<ion-view view-title="Please Sign in">
<ion-content class="padding">
<div class="list">
<label class="item item-input">
<input type="text" placeholder="Name" ng-model="username">
</label>
<label class="item item-input">
<input type="password" placeholder="Password" ng-model="password">
</label>
</div>
<div class="alert alert-danger" role="alert" ng-show="errorMsg">{{errorMsg}}</div>
<button class="button button-full button-balanced" ng-click="postForm()">Sign In</button>
</ion-content>
</ion-view>
<script src="controller.js"></script>
</body>
你可以用有角度的方式来做,就像下面。。这应该是使用ng模型的正确目的 表格:
<body ng-app="apps" ng-controller="PostController as postCtrl">
<ion-view view-title="Please Sign in">
<ion-content class="padding">
<div class="list">
<label class="item item-input">
<input type="text" placeholder="Name" ng-model="username">
</label>
<label class="item item-input">
<input type="password" placeholder="Password" ng-model="password">
</label>
</div>
<div class="alert alert-danger" role="alert" ng-show="errorMsg">{{errorMsg}}</div>
<button class="button button-full button-balanced" ng-click="postForm()">Sign In</button>
</ion-content>
</ion-view>
<script src="controller.js"></script>
</body>
this.inputData={};首先初始化inputData。在定义$scope.postForm=function(){…}之前,您可以修改代码;首先初始化inputData。在定义$scope.postForm=function(){…}之前,您可以修改代码。