我的IONIC应用程序有问题。 我想在$ http.post之后通过$ http.get从nodeJS重新加载我的数据。 这是我的代码:
.controller('todoTodayCtrl',
function($scope, AuthService, API_ENDPOINT, $http, $state, $ionicPopup) {
$http.get(API_ENDPOINT.url + '/today').then(function(result) {
$scope.todaylist = result.data.msg;
});
})
.controller('todoTodayNewCtrl',
function($scope, AuthService, API_ENDPOINT, $http, $state, $ionicPopup){
$scope.today = {
title: ''
};
$scope.todoNewButton = function() {
$http.post(API_ENDPOINT.url + '/today', $scope.today).then(function(result) {
$state.go('menu.todoToday');
}, function(errMsg) {
var alertPopup = $ionicPopup.alert({
title: 'Nelze přidat Todo',
template: errMsg
});
});
};
})
和第一页
<ion-view title="Todo Today" ng-controller="todoTodayCtrl">
<ion-content overflow-scroll="true" padding="true" class="has-header">
<ion-list>
<ion-item class="item-divider" ng-repeat="today in todaylist">{{today.title}} - {{today.time}}</ion-item>
<button class="button button-stable button-block " ui-sref="menu.todoTodayNew">Přidat todo</button>
</ion-list>
</ion-content>
和带表单的页面
<ion-view title="Nové todo today">
<ion-content overflow-scroll="true" padding="true" class="has-header">
<ion-list>
<label class="item item-input">
<span class="input-label">Nový úkol</span>
<input type="text" placeholder="Nová položka" ng-model="today.title">
</label>
<button class="button button-stable button-block " ng-click="todoNewButton()">Přidat todo today</button>
</ion-list>
</ion-content>
答案 0 :(得分:0)
您必须在POST请求回调中的$ scope.todaylist中推送新的今日值:
$http.post(API_ENDPOINT.url + '/today', $scope.today).then(function(result) {
$scope.todaylist.push(result);
$state.go('menu.todoToday');
}, function(errMsg) {
var alertPopup = $ionicPopup.alert({
title: 'Nelze přidat Todo',
template: errMsg
});
});
或者通过$ state将结果传递给你的todoTodayCtl。
$state.go('menu.todoToday', {myParam: {some: 'thing'}})
$stateProvider.state('menu.todoToday', {
url: '/myState',
params: {myParam: null}, ...
然后访问控制器中的参数。
$stateParams.myParam //should be {some: 'thing'}
答案 1 :(得分:0)
我的服务器NodeJs
apiRoutes.post('/today', passport.authenticate('jwt', {session: false}), function(req, res) {
var token = getToken(req.headers);
if (token) {
var decoded = jwt.decode(token, config.secret);
User.findOne({
name: decoded.name
}, function(err, user) {
if (err) throw err;
if (!user) {
return res.status(403).send({success: false, msg: 'Authentication failed. User not found.'});
} else {
console.log(req.body.title);
var newToday = new Today({
title: req.body.title,
time: 'Timeee',
user: user.name
});
newToday.save(function(err) {
if (err) {
res.json({succes: false, msg: 'Error'});
} else {
res.status(200).json({succes: true, msg: newToday});
}
});
}
});
} else {
return res.status(403).send({success: false, msg: 'No token provided.'});
}
});
答案 2 :(得分:0)
解决
public class Point {
private double x, y;
public Point(double x, double y) {
this.x = x;
this.y = y;
}
public static void main(String[] args) {
Point[] objectPoints = new Point[3];
double x[] = {3,4,5};
double y[] = {4,5,6};
for (int i = 0; i < objectPoints.length; i++) {
objectPoints[i] = new Point(x[i], y[i]);
}
}
}