Problem with adding input number

I’m trying to add two numbers in my application. One number is from Database and other I want to insert in the application. It is very simple but I’m new to ionic and angular js. This is my code:

Html :

{{sum()}} app.js

app.js :

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

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

All the app display is number 9 which is $scope.points as in my database it is 9 but it doesn’t add the input number when I try to input any number. Anyone could please help?

If you’re new to Ionic and Angular, I’d strongly recommend you learn Ionic 2 and Angular 2. Major performance improvements. Both frameworks recently went to semantic versioning, so their numbers are now Ionic 3 (not yet stable) and Angular 4 (stable) but they are still basically Ionic 2 and Angular 2. Only prioritize learning Ionic 1 and AngularJS if you need to support legacy code.

1 Like

I totally agree with @AaronSterling, and here’s roughly how your situation would look in Ionic 2:

<ion-input [(ngModel)]="addlPoints" placeholder="additional points"></ion-input>
<div>total points: {{basePoints + addlPoints}}</div>
export class PointsPage {
  basePoints: number;
  addlPoints: number;

  constructor(private _svc: PointsService) {
    this.basePoints = svc.currentPoints();

But i have done a lot of the application in Ionic 1 and this is for uni project so i dont have more time to redo it it in ionic 2. When i add points in html like this :

total points: {{basePoints + addlPoints}}
it works fine. The problem is I want to send the summed points to database. Any idea how to do that ?

You have to create an API on your server that accepts POST requests and inserts/updates your database.

From your controller, you have to do a $ request.