In accordance with the document, Angular services are considered singleton instances.
I am currently developing a time-tracking project where I intend to incorporate multiple tasks.
<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>
Here is an excerpt from my controller:
controller("DashboardCtrl", ['$scope', 'Entry', function ($scope,Entry) {
$scope.data = [];
$scope.addEntry = function() {
$scope.data.push(Entry);
//$scope.data.push(new jEntry());
}
}])
Below is my service definition:
.service('Entry', [function(){
this.project = "";
this.start = "";
this.finish = "";
}]);
My issue arises when I try to create new tasks using a JavaScript constructor (jEntry).
function jEntry() {
this.project = "";
this.start = "";
this.finish = "";
}
When utilizing a service, all tasks seem to be linked as singletons. My question is: what is the appropriate Angular approach for achieving this functionality?