Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Using ng-if directive at the root node of a view messes up the destroy() #1504

Open
mehmetf opened this issue Sep 30, 2014 · 3 comments
Open
Milestone

Comments

@mehmetf
Copy link
Contributor

mehmetf commented Sep 30, 2014

No description provided.

@mehmetf
Copy link
Contributor Author

mehmetf commented Sep 30, 2014

Perhaps this is related to bug #704. When I do something like this:

   bind(RouteInitializerFn, toValue: (Router router, RouteViewFactory views) {
      views.configure({
        'view1': ngRoute(path: '/view1',
            viewHtml: '<div ng-if="true"><h2>View 1</h2></div>'),
        'view2': ngRoute(path: '/view2',
            viewHtml: '<div ng-if="true"><h2>View 2</h2></div>'),
      });
    });

and with html file:

    <a href="#/view1">Switch to View 1</a>
    <a href="#/view2">Switch to View 2</a>
    <div>
      <ng-view></ng-view>
    </div>

I get this switching back and forth views:
image

Removing ng-if directive fixes the problem.

I am trying to do this as a workaround for animating the view transitions. ng-if="true" allows the root node to be injected to DOM via viewport and animates the view.

@mehmetf mehmetf changed the title Using ng-if directive at the beginning of a view messed Using ng-if directive at the root node of a view messes up the destroy() Sep 30, 2014
@naomiblack
Copy link
Contributor

This looks like a bug. We're going to defer until after 0.15 -- as a workaround, if you enclose your HTML in a <div> tag, you should see this work as expected.

<div>
   <a href="#/view1">Switch to View 1</a>
    <a href="#/view2">Switch to View 2</a>
    <div>
      <ng-view></ng-view>
    </div>
</div>

@mehmetf
Copy link
Contributor Author

mehmetf commented Oct 2, 2014

You mean wrap the views with

's:

  bind(RouteInitializerFn, toValue: (Router router, RouteViewFactory views) {
      views.configure({
        'view1': ngRoute(path: '/view1',
            viewHtml: '<div><div ng-if="true"><h2>View 1</h2></div></div>'),
        'view2': ngRoute(path: '/view2',
            viewHtml: '<div><div ng-if="true"><h2>View 2</h2></div></div>'),
      });
    });

Yes, this works.

@naomiblack naomiblack modified the milestones: post v1.0, v1.0 Oct 3, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants