I have a series of projects displayed in divs using ng-repeat. Each div contains a link with the project's id.
My goal is to bind the project id on ng-click to update a factory. This will enable me to share the clicked project's id with another controller that will load only the details data for that project.
Here is how my projects view looks:
<div ng-repeat="detail in projects.details">
<a ng-href="#!/project/project-details" ng-click="setId(detail.project_id)"><span></span></a>
</div>
And here is my factory code:
app.factory('getGoodIdProjectDetails', function (){
var savedId = 1; //Default set to 1
return {
getId : function () {
return savedId;
},
setId:function(idGet){
savedId = idGet;
return savedId;
}
}
});
Below are my two controllers:
function ProjectCtrl($scope, $http, $timeout, getGoodIdProjectDetails) {
$scope.setId = function (idGet) {
$scope.idProjectDetails = getGoodIdProjectDetails.setId(idGet);
};
}
function ProjectDetailsCtrl($scope, $http, $timeout, getGoodIdProjectDetails) {
$scope.idProjectDetails = getGoodIdProjectDetails.getId();
}
Although the console shows an error about binding ng-click, when I inspect the view it appears to be working correctly like ng-click="setId(8)"
.
My aim is for the factory to update with the correct id upon click and then access this id in the projectDetailsCtrl
to load the project information.
|| EDIT ||: After changing the ng-click method, everything is functioning properly. Thank you all!