0

I've defined the following trivial directive

angular.module('my-app').directive('formPanel', function () {

    return {
      restrict: 'EA',
      scope: {
        forms: "=",
        title: "@",
        formSelect: "&"
      },
      templateUrl: 'formPanel.html'
    };
  }
);

the contents of the formPanel.html template are:

<h1>foo</h1>

If I invoke the directive 3 times like so:

<form-panel title="title" forms="entitledApplications" 
    form-select="goToFormDetails(selectedForm)"/>

<form-panel title="title" forms="maybeEntitledApplications" 
    form-select="goToFormDetails(selectedForm)"/>

<form-panel title="title" forms="applications" 
    form-select="goToFormDetails(selectedForm)"/>

The following output is rendered

<h1>foo</h1>

But I was expecting the following

<h1>foo</h1>
<h1>foo</h1>
<h1>foo</h1>

It seems that the problem occurs if the list passed to the forms scope attribute is empty/null, but I don't understand why.

1
  • What browser are you using? Commented Nov 9, 2015 at 12:27

2 Answers 2

2

Try using closing tags for your directive HTML element:

<form-panel title="title" forms="entitledApplications" 
   form-select="goToFormDetails(selectedForm)"></form-panel>

<form-panel title="title" forms="maybeEntitledApplications" 
   form-select="goToFormDetails(selectedForm)"></form-panel>

<form-panel title="title" forms="applications" 
   form-select="goToFormDetails(selectedForm)"></form-panel>
Sign up to request clarification or add additional context in comments.

Comments

1

You can't use self closing tags for custom elements.

Your code works fine with closing tags

<form-panel title="title" forms="entitledApplications" 
    form-select="goToFormDetails(selectedForm)"></form-panel>

DEMO

1 Comment

Thanks, this fixed it

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.