As per document: Angular service are singleton
I am creating a time-tracking project in which i want to add multiple task
<ul>
<li ng-repeat="item in data track by $index" >
<label>Project Name</label>
<input type="text" ng-model="item.project"/>
<label>Start Time</label>
<input type="text" ng-model="item.start"/>
<label>End Time</label>
<input type="text" ng-model="item.finish"/>
</li>
</ul>
<a ng-click="addEntry();">Add Item</a>
and this is my controller
controller("DashboardCtrl", ['$scope', 'Entry', function ($scope,Entry) {
$scope.data = [];
$scope.addEntry = function() {
$scope.data.push(Entry);
//$scope.data.push(new jEntry());
}
}])
and my service
.service('Entry', [function(){
this.project = "";
this.start = "";
this.finish = "";
}]);
My problem is that when i use javascript constructor(jEntry)
function jEntry() {
this.project = "";
this.start = "";
this.finish = "";
}
for creating new task, it works fine, while using service all tasks behave as they are bind to singleton.
So my question is what is the angular way to perform this task?