I am facing a challenge with my custom directive that inserts an HTML block onto the page. The issue is to have a variable within this block that can be manipulated based on an ng-click
function in my controller.
This is what my directive looks like:
.directive('sendModal', function () {
return {
restrict: 'E',
template: '<div ng-click="switchCurrency()">'+currency+'</div>'
};
});
The function in the Controller (using $parent as the modal exists on the parent level):
vm.$parent.switchCurrency = function() {
console.log('clicked switchCurrency');
if (currency === 'USD') {
currency = 'BTC';
} else {
currency === 'USD';
}
};
The error I encounter is: ReferenceError: currency is not defined
I need assistance in figuring out how to declare a variable named currency
inside my directive HTML and make it accessible from the Controller.