Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

ng-transclude doesn't work inside ng-switch-default #4969

Closed

Description

@jbro-io

When nesting ng-transclude inside an ng-switch-default directive the following error is produced:

Error: [ngTransclude:orphan] Illegal use of ngTransclude directive in the template! No parent directive that requires a transclusion found.

Here it is reproduced:
http://plnkr.co/edit/3CEj5OY8uXMag75Xnliq?p=preview

Activity

  1. btford commented on Jan 4, 2014

    @btford
    Contributor

    Confirmed this is an issue on 1.2.7 as well.

  2. dberringer commented on Jan 20, 2014

    @dberringer

    +1

  3. modified the milestones: 1.2.12, 1.2.11, 1.2.13 on Feb 3, 2014
  4. ofpiyush commented on Feb 10, 2014

    @ofpiyush

    +1

  5. modified the milestones: 1.2.14, 1.2.13 on Feb 15, 2014
  6. marbetschar commented on Feb 21, 2014

    @marbetschar

    +1 from here

  7. modified the milestones: 1.3.0-beta.1, 1.2.14 on Mar 1, 2014
  8. 3 remaining items

  9. removed this from the 1.3.0-beta.3 milestone on Mar 24, 2014
  10. tbosch commented on Mar 28, 2014

    @tbosch
    Contributor

    Hi,
    the problem is that ng-switch is using a transclude as well, which leads to the error.

    In your case, you should create a new directive that uses the right $transclude function. For this to work, store the $transclude in the controller of your parent directive (in your case field), and create a new directive that references that controller and uses its $transclude function.

    In your example:

    .directive('field', function() {
      return {
           ....
          controller: ['$transclude', function($transclude) {
            this.$transclude = $transclude;
          }],
          transclude: true,
           ....
      };
    })
    .directive('fieldTransclude', function() {
      return {
        require: '^field',
        link: function($scope, $element, $attrs, fieldCtrl) {
          fieldCtrl.$transclude(function(clone) {
            $element.empty();
            $element.append(clone);
          });
        }
      }
    })
    

    In the html, you then just use <div field-transclude> instead of <div ng-transclude>.

    Here is an updated plunker: http://plnkr.co/edit/au6pxVpGZz3vWTUcTCFT?p=preview

    Closing this as not a bug. Sorry for the late answer and please comment if you think I understood you incorrectly.

  11. vojtajina commented on May 14, 2014

    @vojtajina
    Contributor

    @tbosch I think this is a bug. What you described is a workaround.

  12. tbosch commented on May 14, 2014

    @tbosch
    Contributor

    @vojtajina Do you mean we should have a general solution for this, e.g. allow ng-transclude directive to define the transclude it should use, or only make ng-transclude work nicely with directives that are part of angular core (like ng-switch, ng-if, ng-repeat, ...)?

  13. petebacondarwin commented on May 15, 2014

    @petebacondarwin
    Contributor
  14. axelson commented on Apr 22, 2015

    @axelson

    Note: #7387 was never merged.

  15. chiptus commented on May 31, 2016

    @chiptus

    can we reopen this? it's not fixed

  16. gkalpak commented on May 31, 2016

    @gkalpak
    Member

    @chiptus, it seems pretty fixed to me (up until v1.5.5): http://plnkr.co/edit/M5vcubGIDkKuCeDqD4cc?p=preview
    If you think you have found a bug, please open a new issue, providing the necessary details (e.g. expected vs actual behavior, a demo, steps to reproduce etc). Thx !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions