I have a scenario similar to the following:
<a href="#" title="Post 1" id="car1"> Audi car
</a>
<a href="#" title="Post 1" id="car2"> BMW car
</a>
How can I pass the ID to the controller? I attempted the following:
<a href="#" title="Post 1" id="car1" onclick="getCarID(this.id)" > Audi car </a>
This method works outside of the Angular controller, but I would like it to be inside the controller. It seems that using ng-click
is necessary, however, this.id
will not function. How can this be resolved?
In my controller and getCarID function, I have implemented it as follows:
angular.module('myModule')
.controller('carController', function($scope) {
$scope.getCarID = function(elementID) {
var car = document.getElementById(elementID);
console.log(elementID + " has been clicked");
}
)}
If anything is unclear or requires further explanation, please leave a comment and I will update the question accordingly.
Thank you for your assistance.