sagesky36
sagesky36

Reputation: 4692

attributes for an angular directive

I have a directive which takes in an attribute of "attachmentType".

<attachment attachment-type="CK" />

How can I include another attribute (attachmentId) that gets another value from my page together with the above attribute (basically multiple attributes)?

For instance, below would be another separate attribute,

<attachment attachment-id={{cdmCtrl.copiedRow.CheckDepositHeaderId}} />

I tried something like the following, but syntactically, wasn't correct.

<attachment attachment-type="CK",  attachment-id={{cdmCtrl.copiedRow.CheckDepositHeaderId}} />

Upvotes: 0

Views: 20

Answers (1)

Pankaj Parkar
Pankaj Parkar

Reputation: 136144

As you wanted to pass dynamic value to directive by scope, you need to add that attribute inside isolated scope option of directive with @(one way binding) . You don't need to specify , between two attributes. They will be treated as independent attribute by default.

scope: {
   attachmentId: '@'
}

Inside directive link function/ controller you will get this attachmentId by scope.attachmentId. Also make sure to close out directive element, as its a custom element.

<attachment attachment-type="CK" 
   attachment-id={{cdmCtrl.copiedRow.CheckDepositHeaderId}}>
</attachment>

Upvotes: 1

Related Questions