My custom directive, named "mycomponent", has the following configuration:
restrict: 'AE',
templateUrl: 'template.html',
scope:{
sTransactionType: '=transactionType',
sStorageVariable: '=storageVariable'
},
link: function(scope, element, attrs){
console.log("attrs.transactionType:: "+attrs.transactionType);
console.log("scope.sTransactionType:: "+scope.sTransactionType);
When using the directive in markup like below:
<my-component transaction-Type="FundTransfer" storage-Variable="FundTransferToday"></my-component>
I face an issue where the values of attributes transaction-Type
and storage-Variable
are returning as undefined
when trying to access them in the link
function of the directive.
I have tried changing attribute and scope variable names without success.
How can I successfully retrieve custom directive attribute values into scope variables?
Updated code snippet:
var fundtransfer = angular.module("fundtransfer",['mydirectives']);
var controllers = {};
controllers.cntFundTransfer = function($scope, $rootScope){
}
var mydirectives = angular.module("mydirectives",['Constants']);
mydirectives.directive('myComponent', function($rootScope){
restrict: 'AE',
templateUrl: 'template.html',
scope:{
sTransactionType: '=transactionType',
sStorageVariable: '=storageVariable'
},
link: function(scope, element, attrs){
console.log("scope.sTransactionType:: "+scope.sTransactionType);
}
}
<my-component transaction-type="FundTransfer" storage-variable="FundTransferToday"></my-component>