1

I have the following code

 <div data-ng-repeat="entity in myItems">
     <div data-entity-vignette="true">
     </div>
  </div>

Entity Vignette is defined as an attribute directive here:

.directive('entityVignette', function() {
    return {
        restrict: 'A',
        templateUrl: '../Assets/Scripts/entityVignette.html'
    }
});

and entityVignette.html contains

<div>{{ entity.DisplayName }}</div>

My question, is how can code my template so that entityVignette.html does not depend on the variable name entity

That is, to work with my variable of entity, I must use data-ng-repeat="entity in myItems", how could I make it work so that enitityVignette.html doesn't care if it's named entity or for instance item?

1 Answer 1

1

One way to do it would be to isolate the scope of your directive. For example, declare you directive like this:

.directive('entityVignette', function() {
    return {
        restrict: 'A',
        scope: {nameToDisplay:'='},
        templateUrl: '../Assets/Scripts/entityVignette.html'
    }
});

Use it like this:

 <div data-ng-repeat="entity in myItems">
     <div data-entity-vignette="true" data-name-to-display="entity.DisplayName">
     </div>
  </div>

And in your template just do this:

<div>{{ nameToDisplay }}</div>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.