Answer the question
In order to leave comments, you need to log in
How to use the same directive multiple times?
I wrote my own directive, which should be used several times on the page, but with different data.
As a result, it turns out that it takes data from the last connection and inserts it into all connected directives.
In the markup I connect
<tab heading="Пополнить">
<transaction type="deposit"></transaction>
</tab>
<tab heading="Вывести">
<transaction type="cashout"></transaction>
</tab>
function transaction(){
return {
restrict: 'EA',
replace: true,
transclude: true,
templateUrl: 'directives/transaction/transaction.html',
link: function (scope, element, attrs) {
},
controller: function($scope, $attrs){
var type = $attrs.type;
$scope.textButton = 'Пополнить счет';
switch (type){
case 'deposit':
$scope.textButton = 'Пополнить счет';
break;
case 'cashout':
$scope.textButton = 'Снять';
break;
default:
console.log('мимо');
break;
}
}
}
}
Answer the question
In order to leave comments, you need to log in
Because $scope in the directive will be the same.
UPD: www.plnkr.com
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question