我有两个视图的控制器。我在第一个视图中有一个提交按钮,html代码如下,
<div class="item item-stacked-label" ng-repeat="item in cartItems" >
<div class="row">
<div class="col" ng-model="item.name" ng-class="{hideName: !setActive, showName: setActive}" ng-click="setActive = !setActive ">
<p>{{item.name}}</p>
</div>
<div class="col" ng-model="item.qty" >{{item.qty}}</div>
<div class="col" ng-model="item.price" >{{item.price}}</div>
<div class="col" ng-click="removeItem(index)">X</div>
</div>
<div class="panel2">
<a class="social-button" >Purchase</a>
<a class="social-button" ng-click="delivery(cartItems)" >Delivery</a>
</div>
<div/>
在控制器中,
$scope.delivery = function(deliverItems){
$scope.amount = $scope.getTotal();
if (localStorage.getItem('appLocalStorageUser')!==null){
var data = {
appId : $rootScope.appId,
item : deliverItems,
amount : $scope.amount,
};
$scope.xx = data;
$state.go('app.deliverDetails');
}
else
$state.go('app.login');
}
在第二个视图中,html如下所示,
<div class="item item-stacked-label">
<div class="row2">
<div>Name</div>
<input type="text" ng-model="details.name" style="width:100%; height:20px; margin: 0px 10px; border: 1px groove gray;">
</div>
<div class="row2">
<div>Address</div>
<input type="text" ng-model="details.address" style="width:100%; height:20px; margin: 0px 10px; border: 1px groove gray;">
</div>
<div class="row2">
<div>Contact number</div>
<input type="number" ng-model="details.number" style="width:100%; height:20px; margin: 0px 10px; border: 1px groove gray;">
</div>
</div>
<div class="panel2">
<a class="social-button" ng-click="deliver(details)" >Deliver</a>
</div>
在同一个控制器中,编写下面的函数以获取交付按钮的提交详细信息,
$scope.deliver = function(deliverDetails){
console.log(deliverDetails);
console.log($scope.xx);
}
路线如下,
.state('app.cart', {
url: '/cart',
views: {
'menuContent': {
templateUrl: 'templates/cart.html',
controller: 'cartCtrl'
}
}
})
.state('app.deliverDetails', {
url: '/deliverDetails',
views: {
'menuContent': {
templateUrl: 'templates/deliverDetails.html',
controller: 'cartCtrl'
}
}
});
但$scope.xx
未定义。我不懂。两个功能都在同一个控制器中。请帮忙