Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript angularjs ionic应用程序添加两个数字,一个来自数据库,另一个来自输入_Javascript_Angularjs_Ionic Framework_Backand - Fatal编程技术网

Javascript angularjs ionic应用程序添加两个数字,一个来自数据库,另一个来自输入

Javascript angularjs ionic应用程序添加两个数字,一个来自数据库,另一个来自输入,javascript,angularjs,ionic-framework,backand,Javascript,Angularjs,Ionic Framework,Backand,我正在尝试在我的应用程序中添加两个数字。一个数字来自数据库,另一个我想插入到应用程序中。这很简单,但我对angularjs是新手。这是我的代码: Html: <div class="item-input-inset"> <label class="item-input-wrapper"> <input type="number" placeholder="Insert Points" ng-model="inp"/> </label>

我正在尝试在我的应用程序中添加两个数字。一个数字来自数据库,另一个我想插入到应用程序中。这很简单,但我对angularjs是新手。这是我的代码:

Html:

<div class="item-input-inset">
 <label class="item-input-wrapper">
    <input type="number" placeholder="Insert Points" ng-model="inp"/>
   </label>
   </div>
   <span> {{sum()}} </span>app.js

所有的应用程序显示都是数字9,即$scope.points,在我的数据库中是9,但当我尝试输入任何数字时,它不会添加输入数字。任何人都可以帮忙吗?

我根据您的代码制作了一个运行演示,它似乎运行良好

函数ctrl($scope,$timeout){
$scope.points=0;
$scope.inp=0;
$scope.sum=函数(){
返回$scope.points+$scope.inp;
}
getMyPoints();
函数getMyPoints(){
//模拟服务
$timeout(函数(){
$scope.points=9;
}, 1000);
}
}

{{sum()}}app.js

这是整个app.js。删除点功能尚未完成

 // Ionic Starter App
// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a          <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
angular.module('starter', ['ionic', 'backand'])

.config(function (BackandProvider) {
BackandProvider.setAppName('dozr');
BackandProvider.setAnonymousToken('00890966-560c-49a9-96af-8203d8645186');
})

 .controller('AppCtrl', function($scope, PointService) {
$scope.points = 0;
$scope.inp = 0;



 function getMyPoints() {
 PointService.getPoints()
 .then(function (result) {
  $scope.points = result.data.name;
 });
 }

 $scope.sum = function(){ 
 return $scope.points + $scope.inp }



 $scope.addPoint = function() {

  PointService.addPoint($scope.sum)
 .then(function(result) {
  $scope.input = 0;
  // Reload our points, not super cool
  getMyPoints();
});
}

//$scope.deletePoint = function(id) {
//PointService.deletePoint(id)
//.then(function (result) {
  // Reload our points, not super cool
  //getAllPoints();
// });
//}

// getMyPoints();
//})

.service('PointService', function ($http, Backand) {
var baseUrl = '/1/objects/';
var objectName = 'points/';



function getUrl() {
return Backand.getApiUrl() + baseUrl + objectName;
}

function getUrlForId(id) {
return getUrl() + id;
}

getPoints = function (id) {
return $http.get(getUrlForId(1));
};

addPoint = function(point) {
return $http.put(getUrlForId(1), point);
}

deletePoint = function (id) {
return $http.delete(getUrlForId(id));
};

return {
getPoints: getPoints,
addPoint: addPoint,
deletePoint: deletePoint
}
});
//Ionic Starter应用程序
//angular.module是创建、注册和检索angular模块的全局位置
//“starter”是此角度模块示例的名称(也在index.html中的属性中设置)
//第二个参数是“requires”的数组
角度模块('starter'、['IONAL'、'backand']))
.config(函数(BackandProvider){
BackandProvider.setAppName('dozr');
BackandProvider.setAnonymousToken('00890966-560c-49a9-96af-8203d8645186');
})
.controller('AppCtrl',函数($scope,PointService){
$scope.points=0;
$scope.inp=0;
函数getMyPoints(){
PointService.getPoints()
.然后(函数(结果){
$scope.points=result.data.name;
});
}
$scope.sum=函数(){
返回$scope.points+$scope.inp}
$scope.addPoint=函数(){
PointService.addPoint($scope.sum)
.然后(函数(结果){
$scope.input=0;
//重新加载我们的积分,不是超级酷
getMyPoints();
});
}
//$scope.deletePoint=函数(id){
//PointService.deletePoint(id)
//.然后(函数(结果){
//重新加载我们的积分,不是超级酷
//getAllPoints();
// });
//}
//getMyPoints();
//})
.service('PointService',函数($http,Backand){
var baseUrl='/1/objects/';
var objectName='points/';
函数getUrl(){
返回Backand.getapirl()+baseUrl+objectName;
}
函数getUrlForId(id){
返回getUrl()+id;
}
getPoints=函数(id){
返回$http.get(getUrlForId(1));
};
addPoint=函数(点){
返回$http.put(getUrlForId(1),点);
}
deletePoint=函数(id){
返回$http.delete(getUrlForId(id));
};
返回{
获取点:获取点,
addPoint:addPoint,
deletePoint:deletePoint
}
});

我不在我的应用程序中工作,我不知道为什么。它只在我这样做时起作用:{{points+inp}},但我想将$scope.sum添加到数据库中以更新数据库中的点,这就是为什么这个解决方案对我没有好处。你知道为什么它在我的应用程序中不起作用吗?你可以显示更多的控制器,包括你的作用域和DB调用。你需要调用
getMyPoints()
来设置DB中的值。检查我编辑的答案。如果我这样做,$scope.points将始终为9?问题不在于scope.points,我认为当函数sum显示它时,问题在于scope.inp,因为函数sum无法将其添加到scope.points?
 // Ionic Starter App
// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a          <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
angular.module('starter', ['ionic', 'backand'])

.config(function (BackandProvider) {
BackandProvider.setAppName('dozr');
BackandProvider.setAnonymousToken('00890966-560c-49a9-96af-8203d8645186');
})

 .controller('AppCtrl', function($scope, PointService) {
$scope.points = 0;
$scope.inp = 0;



 function getMyPoints() {
 PointService.getPoints()
 .then(function (result) {
  $scope.points = result.data.name;
 });
 }

 $scope.sum = function(){ 
 return $scope.points + $scope.inp }



 $scope.addPoint = function() {

  PointService.addPoint($scope.sum)
 .then(function(result) {
  $scope.input = 0;
  // Reload our points, not super cool
  getMyPoints();
});
}

//$scope.deletePoint = function(id) {
//PointService.deletePoint(id)
//.then(function (result) {
  // Reload our points, not super cool
  //getAllPoints();
// });
//}

// getMyPoints();
//})

.service('PointService', function ($http, Backand) {
var baseUrl = '/1/objects/';
var objectName = 'points/';



function getUrl() {
return Backand.getApiUrl() + baseUrl + objectName;
}

function getUrlForId(id) {
return getUrl() + id;
}

getPoints = function (id) {
return $http.get(getUrlForId(1));
};

addPoint = function(point) {
return $http.put(getUrlForId(1), point);
}

deletePoint = function (id) {
return $http.delete(getUrlForId(id));
};

return {
getPoints: getPoints,
addPoint: addPoint,
deletePoint: deletePoint
}
});