I am working on a list of apartments displayed using ng-repeat. I need each apartment to be a clickable link that directs the user to view more details about that specific apartment. However, I am facing an issue where the links are not being repeated dynamically for each apartment. Can anyone suggest a solution?
app.controller("apartmentSizeController", ['$scope', '$stateParams', function($scope, $stateParams){
$scope.id = $stateParams.id;
let apartments = [];
$scope.apartments = apartments;
$scope.apartmentTemplate = [{
"id": 1,
"apartmentName": "Park Dearborn",
"apartmentDescription": "",
"amenityLink": "amenities({id:1})",
"neighborhoodLink": "neighborhood({id:1})",
"apartmentImage": "",
"apartments" : [{
"name" : "Studio",
"amenityDescription" : "make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting,",
"apartmentTypeImage" : "",
"typesOfApartments" : ["Pullman", "Kitchenette", "Galley", "Southbookcase", "Northbookcase"],
"apartmentLink" : ["link", "link", "link", "etc. a link for each"]
},
{
"name" : "One Bedroom",
"amenityDescription" : "make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting,",
"apartmentTypeImage" : "",
"typesOfApartments" : ["Northeast", "North", "Northwest", "Southwest", "Northbookcase"],
"apartmentLink" : ["link", "link"]
}]
},
{
"id": 2,
"apartmentName": "Dearborn North",
"apartmentDescription": "Amazingly beautiful apartments please put more stuff here",
"amenityLink": "amenities({id:2})",
"neighborhoodLink": "neighborhood({id:2})",
"apartmentImage": "",
"apartments" : [{
"name" : "Convertible",
"amenityDescription" : "make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting,",
"apartmentTypeImage" : "",
"typesOfApartments" : ["Style1", "Style2"],
"apartmentLink" : ["link"]
},
{
"name" : "Studio",
"amenityDescription" : "make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting,",
"apartmentTypeImage" : "",
"typesOfApartments" : ["Style1", "Style2"],
"apartmentLink" : ["link", "link", "link"]
},
{
"name" : "One Bedroom",
"amenityDescription" : "make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting,",
"apartmentTypeImage" : "",
"typesOfApartments" : ["Style1", "Style2"],
"apartmentLink" : ["link"]
}]
}];
var x = $scope.apartmentTemplate.indexOf($scope.apartmentTemplate[$scope.id]);
for (let i = 0; i < $scope.apartmentTemplate.length; i++) {
if ($scope.apartmentTemplate[i].id == $scope.id) {
console.log("found index " + $scope.apartmentTemplate[i].id);
$scope.buildingImage = $scope.apartmentTemplate[i].apartmentImage;
$scope.apartmentDescription = $scope.apartmentTemplate[i].apartmentDescription;
$scope.amenityLink = $scope.apartmentTemplate[i].amenityLink;
$scope.neighborhoodLink = $scope.apartmentTemplate[i].neighborhoodLink;
$scope.apartmentLink = $scope.apartmentTemplate[i].apartments[i].apartmentLink[i];
$scope.apartments = $scope.apartmentTemplate[i].apartments;
} else {
console.log("not found");
}
};
}]);
This is my view
<div ng-controller="apartmentSizeController" class="apartment-details-container" style="border: 2px solid rgb(101,0,0);">
<div class="apartment-details" style="background-color: white;">
<div class="amenity-title" style="color: rgb(101,0,0); background-color: white; width: 350px; margin: 1em;">
<p><span style="font-size: 28px; color: rgb(101,0,0); font-family: crimson text, sans-serif;letter-spacing: 1.2;">APARTMENTS</span></p>
<p style="font-family: sans-serif;">{{apartmentDescription}}<!---->
</p>
<h1>ID is {{id}}</h1>
<a ui-sref={{amenityLink}}><h3 style="color: rgb(101,0,0);; font-family: sans-serif;">view amenities</h3></a>
<a ui-sref={{neighborhoodLink}}><h3 style="color: rgb(101,0,0);; font-family: sans-serif;">view neighborhood</h3></a>
<p ng-click="goBack()"><a href="#" style="color: rgb(101,0,0);font-family: Crimson-text, sans-serif;">back</a></p>
</div>
<div><img style="width: 100%;" height="416"; src={{buildingImage}} /></div>
</div>
</div><!-- end of apartment details container-->
<div class="property-grid">
<div ng-controller="apartmentSizeController" class="property-grid-item" ng-repeat="apartment in apartments">
<div class="frame-two"><img src={{apartment.apartmentTypeImage}} alt="park dearborn"></div>
<div class="apartment-info"><p><span class="font-title">{{apartment.name}}
<aside>
<a href="??">
<h4 ng-repeat="type in apartment.typesOfApartments"> {{type}}</h4>
</a>
</aside>
</div><!--end apartment info-->
</div><!--property-grid-item-->
</div>
</div>
</div><!--end main -content-->
What would be the best way to ensure that each apartment's link appears beside it? For example: "typesOfApartments" : ["Pullman", "Kitchenette", "Galley", "et."], "apartmentLink" : ["link", "link", "link", "etc. a link for each"]