Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

AngularJS two different actions in ng-submit

var myApp = angular.module("myList", []);

myApp.controller("myListController", function($scope) {
    $scope.items = [];
    $scope.isEdit = false; // initialize
    $scope.editingIndex = null;  //initialize
    $scope.newItem = function() {
     if(!$scope.isEdit){  //if not in edit mode -> add new
       $scope.items.push({description:$scope.description, amount: $scope.amount});

     }
      else{  //in edit mode -> edit the object
        $scope.items[$scope.editingIndex] = {  //replace with new values
          description:$scope.description, amount: $scope.amount
        }
        $scope.isEdit = false;    //setting back to false
        $scope.editingIndex = null;
      }
            $scope.description = '';
            $scope.amount = 0
    };

    $scope.deleteItem = function(index) {
        $scope.items.splice(index, 1);
    }

    $scope.totalPrice = function() {
        var total = 0;
        for(count=0; count<$scope.items.length;count++){
            total += $scope.items[count].amount;
        }
        return total;
    };
Comment

PREVIOUS NEXT
Code Example
Javascript :: angularjs How to get time difference from ZoneDateTime in javascript 
Javascript :: tabbarbadge style react native 
Javascript :: Angularjs to Angular Migration: factory prototype 
Javascript :: angularjs NodeJS server performs POST request, but returns HTTPErrorResponse 
Javascript :: AngularJS stuck in module 
Javascript :: Angular.js : recursive call to an $mdDialog controller 
Javascript :: Check AngularJS checkbox with Selenium 
Javascript :: How to increase/decrease value with reducer 
Javascript :: How to spread state into a specific array 
Javascript :: Use of typescript generics for extended parametres 
Javascript :: Add and remove required attribute based on whether it is visible or hidden 
Javascript :: access language in request express 
Javascript :: react open popup to upload image file 
Javascript :: Node.js and Express session handling - Back button problem 
Javascript :: debouce with clear debounce function javascript 
Javascript :: useEffect in React 18 in strictmode 
Javascript :: audio js fast 
Javascript :: Uncaught Error: spawn node 
Javascript :: javascript object access time complexity 
Javascript :: for in loop of javascript 
Javascript :: var a = x || y Variable Assignment In JavaScript 
Javascript :: auto load in element show 
Javascript :: how to get creator of inetarceton discordjs 
Javascript :: Turn A 2D Array Into A JSON 
Javascript :: send a message in the first channel discord.js 
Javascript :: useState intro 
Javascript :: JSON of first block in cryptocurrency blockchain 
Javascript :: Check If Backbone Model Has Property 
Javascript :: ES6 reactjs problems 
Javascript :: var date = new Date(); 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =