Repository: angular
Issue: Upgraded AngularJS component broken transclusion under ng-if
Labels: type: bug/fix,area: upgrade,state: needs more investigation,P4

<!--🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅

Oh hi there! 😄

To expedite issue processing please search open and closed issues before submitting a new one.
Existing issues often contain information about workarounds, resolution, or progress updates.

🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅-->


# 🐞 bug report

### Affected Package
<!-- Can you pin-point one or more @angular/* packages as the source of the bug? -->
<!-- ✍️edit: --> The issue is caused by package @angular/upgrade/static


### Is this a regression?

<!-- Did this behavior use to work in the previous version? -->
<!-- ✍️--> Not sure


### Description

<!-- ✍️--> 

With situation described below when `ng-if` adds content, transclusion happens correctly only once - next times ng-if adds content, components on the transcluded content are not initialized

```html
<aio-app> <!-- downgraded aio component -->
  <ajs-show-hide> <!--  upgraded ajs component -->
    <button ng-init="shown = false" ng-click="shown = !shown">Show/Hide</button>
    <div ng-if="shown">
      <ng-transclude>
        <aio-counter> <!-- native aio component, transcluded by aio-app into ajs-show-hide -->
          <ajs-counter> <!--  upgraded ajs component -->
            <button ng-init="count = 0" ng-click="count = count + 1">Bump!</button>
            Count: {{count}}
          </ajs-counter>
        </aio-counter>
      </ng-transclude>
    </div>
  </ajs-show-hide>
</aio-app>
```

## 🔬 Minimal Reproduction
<!--
Please create and share minimal reproduction of the issue starting with this template: https://stackblitz.com/fork/angular-issue-repro2
-->
<!-- ✍️--> 
1. go to https://stackblitz.com/edit/angular-puip4w?file=src%2Findex.html
2. click `Show/Hide` button
3. click `Bump!` button
4. ensure Count is updated
5. click `Show/Hide` button again, so that counter is hidden
6. click `Show/Hide` button again, so that counter is shown again
7. observe counter being in previous state (count shows the number of the last count visible) - this is not expected, it should be set to 0
8.  click `Bump!` button
9. counter is not updated - the component is broken

Alternatively:

1. clone https://github.com/zuzusik/angular-upgrade-bug
2. run `npm install`
3. run `ng serve`
4. open http://localhost:4201/
5. go to the step 2 from the list above

<!--
If StackBlitz is not suitable for reproduction of your issue, please create a minimal GitHub repository with the reproduction of the issue. Share the link to the repo below along with step-by-step instructions to reproduce the problem, as well as expected and actual behavior.

Issues that don't have enough info and can't be reproduced will be closed.

You can read more about issue submission guidelines here: https://github.com/angular/angular/blob/master/CONTRIBUTING.md#-submitting-an-issue
-->

## 🔥 Exception or Error
<pre><code>
No errors
</code></pre>


## 🌍  Your Environment

**Angular Version:**
<pre><code>
Angular CLI: 7.3.3
Node: 8.12.0
OS: darwin x64
Angular: 7.2.7
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router, upgrade

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.13.3
@angular-devkit/build-angular     0.13.3
@angular-devkit/build-optimizer   0.13.3
@angular-devkit/build-webpack     0.13.3
@angular-devkit/core              7.3.3
@angular-devkit/schematics        7.3.3
@angular/cli                      7.3.3
@ngtools/webpack                  7.3.3
@schematics/angular               7.3.3
@schematics/update                0.13.3
rxjs                              6.3.3
typescript                        3.2.4
webpack                           4.29.0
</code></pre>

**Anything else relevant?**
<!-- ✍️Is this a browser specific issue? If so, please specify the browser and version. -->

<!-- ✍️Do any of these matter: operating system, IDE, package manager, HTTP server, ...? If so, please mention it below. -->

If we get rid of `<aio-counter>` level and transclude `<ajs-counter>` instead - the bug is also reproducible

AngularJS version is `1.7.7`, reproducible as well on older versions