I have created a component in AngularJS for reusable buttons. I need to pass button text into a function argument via ng-click event of the same button. However, I am unable to get the button text in a function call.
Any help would be much appreciated.
Below is my code.
Index.html
<div class="object-actions" ng-repeat="val in value">
<button-control ng-repeat="v in val" name="{{v}}"></button-control>
</div>
Component
(function() {
"use strict";
angular
.module("buttonCtrl", [])
.component("buttonControl", {
template: `<button ng-click="getName('$ctrl.name')">{{$ctrl.name}}</button>`,
controller: buttonCtrl,
bindings: {
name: "@"
}
});
buttonCtrl.$inject = ["$scope"];
function buttonCtrl($scope) {
$scope.getName = function(name) {
alert(name);
};
}
})();
Output enter image description here
