javascript - Temporary form data to table as object in Angular -


what trying take 4-5 inputs in form, store object , when user selects 'save', temporarily store in session , able access show object in row in table on same page , allow user enter data form input again add next object.

so in end, user may enter 1 object or 6 , when done, allow user submit objects array of objects or effect.

so not angular power user, figure has power somewhere. questions evolve around approach , maybe trying find example or so. of able on this?

thanks much.

well, quite easy if have table , form on same page. can use 1 scope variable array of entered objects , 1 scope variable current object itself.

i'll example without of requirements (e.g. user can enter 6 objects most), should quite straight forward implement.

first take html:

<form ng-controller="rolescontroller">     <label for="name">name</label>     <input type="text" id="name" ng-model="current.name">     <label for="slug">slug</label>     <input type="text" id="slug" ng-model="current.slug">     <label for="level">level</label>     <input type="number" id="level" ng-model="current.level">     <!-- buttons -->     <button type="button" ng-click="storetemp()">store temporarily</button>     <button type="button" ng-click="storeall()">store all</button> </form> 

and controller:

angular.module('administration').controller('rolescontroller',     ['$scope', '$http', function($scope, $http) {      $scope.current = {};     $scope.all = [];      $scope.storetemp = function() {         /* validation here or in html before ... */         $scope.all.push($scope.current);         $scope.current = {};     };      $scope.storeall = function() {         /* maybe validation ... */         $http.post('admin/roles', { roles: $scope.all });     };  }); 

obviously use same button both actions if require user input same amount of new objects.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -