I have a "Start" button when I click on it, the object should be created var dateBegin = new Date(); but not added to the table. After clicking the "stop" button, an object should be created var dateEnd = new Date(); and add the dateBegin and dateEnd objects to the table, that is, the start time and the end time.

Everything works, only when you click on the Stop button, two identical time values ​​are added to the table, but it is necessary that there be a start time and a end time.
How to do it?

enter image description here

 <!doctype html> <html ng-app="purchaseApp"> <head> <meta charset="utf-8"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css"> <link rel="stylesheet" href="styles/style.css"> </head> <body ng-controller="purchaseController"> <div class="panel"> <div class="form-inline"> <div class="form-group"> <div class="col-md-8"> <input class="form-control" ng-model="text" placeholder = "What are you working on?" /> </div> </div> <div class="form-group"> <div class="col-md-2" ng-controller="myCtrl"> <select class="inputProject" ng-model="project"> <option value="{{item.key}}" ng-disabled="item.key==project" ng-repeat="item in items">{{item.value}}</option> </select> </div> </div> <div class="form-group"> <div class="col-md-8"> <input class="secundomer" ng-model="timer" placeholder = "0 Sec" /> </div> </div> <div class="form-group"> <div class="col-md-2"> <button class="btn btn-start" ng-click="addItem1(dateBegin)">Start</button> <button class="btn btn-stop" ng-click="addItem(text,project,dateBegin,dateEnd)">Stop</button> </div> </div> <table class="table table-striped"> <thead> <tr> </tr> </thead> <tbody> <tr ng-repeat="item in list.items"> <td>{{item.purchase}}</td> <td>{{item.value}}</td> <td>{{item.dateBegin}} </td> <td>{{item.dateEnd}} </td> <td>{{item.date}} </td> </tr> </tbody> </table> </div> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js"></script> <script> var model = { items: [ ] }; var purchaseApp = angular.module("purchaseApp", []); purchaseApp.controller("myCtrl", function($scope) { $scope.project="select project"; $scope.items =[ { value:"select project" }, { value:"timer" }, { value:"timer1" }, ]; }); purchaseApp.controller("purchaseController", function ($scope) { $scope.list = model; $scope.addItem1 = function (dateBegin) { var dateBegin = new Date(); } $scope.addItem = function (text, project,,dateBegin,dateEnd,date) { var dateEnd = new Date(); var dateBegin = new Date(); if(text != "") // если текст установлен и введено число, то добавляем { $scope.list.items.push({ purchase: text, project: project,dateEnd: dateEnd.toLocaleTimeString(),dateBegin: dateBegin.toLocaleTimeString()); } } }); var visible = true; function addItem(text,project,date) { if(visible) { document.getElementById('btn btn-stop' ).style.display = 'none'; visible = false; } else { document.getElementById('btn btn-stop' ).style.display = 'block'; visible = true; } } </script> </body> </html> 
  • nothing is clear. What a piece of code? what is he supposed to do? where is the markup to all this? - Grundy
  • one
    did not become clearer, try to formulate the question - Grundy
  • left to add a description of what is wrong in the added code - Grundy
  • sorry, this is my first time here, I don't know what's what - Dmitriy
  • one
    @ Dmitry, the main thing is to ask a question. So far added: what to do and some piece of code. The question itself is not. That is, it’s not known what this piece doesn’t fit - maybe it shows some errors, and maybe it works like that - Grundy

1 answer 1

 $scope.addItem = function (text, project,,dateBegin,dateEnd,date) { 

Syntax error.

 var visible = true; function addItem(text,project,date) { if(visible) { document.getElementById('btn btn-stop' ).style.display = 'none'; visible = false; } else { document.getElementById('btn btn-stop' ).style.display = 'block'; visible = true; } } 

And this and everything connected with it, delete.

  • all the same not that, it turns out when I press stop the start time with the final one coincides - Dmitriy