【发布时间】:2016-12-19 09:56:08
【问题描述】:
我是 Ionic 的新手,我正在开发一个包含两页的演示。第一页包含一个包含 3 个字段的表单。来自三个输入的所有这些值都存储在一个数组中。我想在第二页中以表格格式显示数组,但我做不到。如何在第二页显示数组?
第一页:
第二页:
第一页 HTML:
<form class="form-horizontal" role="form">
<div class="form-group">
<label class="control-label col-sm-2" for="email">Name:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="name" placeholder="Enter Name" ng-model="contact.name">
<div>{{contact.name}}
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="pwd">Email:</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="email" placeholder="Enter Email" ng-model="contact.email">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="pwd">Mobile No:</label>
<div class="col-sm-10">
<input type="tel" class="form-control" id="mobile" placeholder="Enter Mobile" ng-model="contact.mobile">
</div>
</div>
{{contact}}
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary" ng-click="submit(contact)">Submit</button>
</div>
</div>
</form>
第二页HTML:
<div class="jumbotron" >
<table class="table table-hover" >
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Mobile</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="x in contacts track by $index">
<td>{{x.name}} </td>
<td>{{x.email}}</td>
<td>{{x.mobile}}</td>
</tr>
</tbody>
</table>
</div>
</ion-content>
app.js
controller('Home', function($scope,$stateParams,contact){
$scope.contacts = [];
/*$scope.contact ={};*/
console.log($scope.contacts.length);
console.log($scope.contacts);
$scope.submit = function(contact) {
// console.log('am in');
$scope.contacts.push(contact);
console.log($scope.contacts);
refresh();
};
var refresh = function() {
$scope.contact = '';
};
$scope.removeItem = function(x) {
var index = $scope.contacts.indexOf(x);
alert("deleting" + index);
$scope.contacts.splice(index, 1);
}
$scope.editItem = function(x) {
$scope.current = x;
}
$scope.save=function(x){
$scope.current={};
}
})
【问题讨论】:
标签: angularjs ionic-framework hybrid-mobile-app