New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrading a Ng1Component and using $element does not work #13912
Comments
Can confirm... Whereas a pure ng1 component has $element available in $onInit (as per the documentation). An upgraded ng1 component does not have $element available in $onInit until after sometime. |
This sounds like an |
@gkalpak I used |
The title mentions |
Fair enough, the title is a bit wrong (updated it) but the point is that the $element behaves differently in an ng1 component than in a ng2 component. |
Sure. Just trying to figure out where the problem lies (it makes it easier to fix 😛) |
Any progress? |
I am still looking into it. In the meantime, it doesn't seem right to try to access the content of the element in |
…controller Previously, the relative order of the AngularJS compiling/linking operations was not similar to AngularJS's, resulting in inconsistent behavior for upgraded components (which made upgrading to Angular less straight forward). This commit fixes it, by following the compiling/linking process of AngularJS more closely. Main differences: - The components view is already populated when the controller is instantiated (and subsequent hooks are called). - The correct DOM content is available when running the `$onChanges`, `$onInit`, `$doCheck` hooks. Previously, the "content children" were still present, not the "view children". - The same for pre-linking. - The template is compiled in the correct DOM context (e.g. has access to ancestors). Previously, it was compiled in isolation, inside a dummy element. For reference, here is the order of operations: **Before** 1. Compile template 2. Instantiate controller 3. Hook: $onChanges 4. Hook: $onInit 5. Hook: $doCheck 6. Pre-linking 7. Collect content children 8. Insert compiled template 9. Linking 10. Post-linking 11. Hook: $postLink **After** 1. Collect content children 2. Insert template 3. Compile template 4. Instantiate controller 5. Hook: $onChanges 6. Hook: $onInit 7. Hook: $doCheck 8. Pre-linking 9. Linking 10. Post-linking 11. Hook: $postLink Fixes angular#13912
I have a potential fix for this in #14289 (that will make the compiling/instantiating/linking process more similar to AngularJS's in general). |
…controller Previously, the relative order of the AngularJS compiling/linking operations was not similar to AngularJS's, resulting in inconsistent behavior for upgraded components (which made upgrading to Angular less straight forward). This commit fixes it, by following the compiling/linking process of AngularJS more closely. Main differences: - The components view is already populated when the controller is instantiated (and subsequent hooks are called). - The correct DOM content is available when running the `$onChanges`, `$onInit`, `$doCheck` hooks. Previously, the "content children" were still present, not the "view children". - The same for pre-linking. - The template is compiled in the correct DOM context (e.g. has access to ancestors). Previously, it was compiled in isolation, inside a dummy element. For reference, here is the order of operations: **Before** 1. Compile template 2. Instantiate controller 3. Hook: $onChanges 4. Hook: $onInit 5. Hook: $doCheck 6. Pre-linking 7. Collect content children 8. Insert compiled template 9. Linking 10. Post-linking 11. Hook: $postLink **After** 1. Collect content children 2. Insert template 3. Compile template 4. Instantiate controller 5. Hook: $onChanges 6. Hook: $onInit 7. Hook: $doCheck 8. Pre-linking 9. Linking 10. Post-linking 11. Hook: $postLink Fixes angular#13912
…controller Previously, the relative order of the AngularJS compiling/linking operations was not similar to AngularJS's, resulting in inconsistent behavior for upgraded components (which made upgrading to Angular less straight forward). This commit fixes it, by following the compiling/linking process of AngularJS more closely. Main differences: - The components view is already populated when the controller is instantiated (and subsequent hooks are called). - The correct DOM content is available when running the `$onChanges`, `$onInit`, `$doCheck` hooks. Previously, the "content children" were still present, not the "view children". - The same for pre-linking. - The template is compiled in the correct DOM context (e.g. has access to ancestors). Previously, it was compiled in isolation, inside a dummy element. For reference, here is the order of operations: **Before** 1. Compile template 2. Instantiate controller 3. Hook: $onChanges 4. Hook: $onInit 5. Hook: $doCheck 6. Pre-linking 7. Collect content children 8. Insert compiled template 9. Linking 10. Post-linking 11. Hook: $postLink **After** 1. Collect content children 2. Insert template 3. Compile template 4. Instantiate controller 5. Hook: $onChanges 6. Hook: $onInit 7. Hook: $doCheck 8. Pre-linking 9. Linking 10. Post-linking 11. Hook: $postLink Fixes angular#13912
…controller Previously, the relative order of the AngularJS compiling/linking operations was not similar to AngularJS's, resulting in inconsistent behavior for upgraded components (which made upgrading to Angular less straight forward). This commit fixes it, by following the compiling/linking process of AngularJS more closely. Main differences: - The components view is already populated when the controller is instantiated (and subsequent hooks are called). - The correct DOM content is available when running the `$onChanges`, `$onInit`, `$doCheck` hooks. Previously, the "content children" were still present, not the "view children". - The same for pre-linking. - The template is compiled in the correct DOM context (e.g. has access to ancestors). Previously, it was compiled in isolation, inside a dummy element. For reference, here is the order of operations: **Before** 1. Compile template 2. Instantiate controller 3. Hook: $onChanges 4. Hook: $onInit 5. Hook: $doCheck 6. Pre-linking 7. Collect content children 8. Insert compiled template 9. Linking 10. Post-linking 11. Hook: $postLink **After** 1. Collect content children 2. Insert template 3. Compile template 4. Instantiate controller 5. Hook: $onChanges 6. Hook: $onInit 7. Hook: $doCheck 8. Pre-linking 9. Linking 10. Post-linking 11. Hook: $postLink Fixes angular#13912
…controller Previously, the relative order of the AngularJS compiling/linking operations was not similar to AngularJS's, resulting in inconsistent behavior for upgraded components (which made upgrading to Angular less straight forward). This commit fixes it, by following the compiling/linking process of AngularJS more closely. Main differences: - The components view is already populated when the controller is instantiated (and subsequent hooks are called). - The correct DOM content is available when running the `$onChanges`, `$onInit`, `$doCheck` hooks. Previously, the "content children" were still present, not the "view children". - The same for pre-linking. - The template is compiled in the correct DOM context (e.g. has access to ancestors). Previously, it was compiled in isolation, inside a dummy element. For reference, here is the order of operations: **Before** 1. Compile template 2. Instantiate controller 3. Hook: $onChanges 4. Hook: $onInit 5. Hook: $doCheck 6. Pre-linking 7. Collect content children 8. Insert compiled template 9. Linking 10. Post-linking 11. Hook: $postLink **After** 1. Collect content children 2. Insert template 3. Compile template 4. Instantiate controller 5. Hook: $onChanges 6. Hook: $onInit 7. Hook: $doCheck 8. Pre-linking 9. Linking 10. Post-linking 11. Hook: $postLink Fixes angular#13912
…controller Previously, the relative order of the AngularJS compiling/linking operations was not similar to AngularJS's, resulting in inconsistent behavior for upgraded components (which made upgrading to Angular less straight forward). This commit fixes it, by following the compiling/linking process of AngularJS more closely. Main differences: - The components view is already populated when the controller is instantiated (and subsequent hooks are called). - The correct DOM content is available when running the `$onChanges`, `$onInit`, `$doCheck` hooks. Previously, the "content children" were still present, not the "view children". - The same for pre-linking. - The template is compiled in the correct DOM context (e.g. has access to ancestors). Previously, it was compiled in isolation, inside a dummy element. For reference, here is the order of operations: **Before** 1. Compile template 2. Instantiate controller 3. Hook: $onChanges 4. Hook: $onInit 5. Hook: $doCheck 6. Pre-linking 7. Collect content children 8. Insert compiled template 9. Linking 10. Post-linking 11. Hook: $postLink **After** 1. Collect content children 2. Insert template 3. Compile template 4. Instantiate controller 5. Hook: $onChanges 6. Hook: $onInit 7. Hook: $doCheck 8. Pre-linking 9. Linking 10. Post-linking 11. Hook: $postLink Fixes angular#13912
…controller (#14289) Previously, the relative order of the AngularJS compiling/linking operations was not similar to AngularJS's, resulting in inconsistent behavior for upgraded components (which made upgrading to Angular less straight forward). This commit fixes it, by following the compiling/linking process of AngularJS more closely. Main differences: - The components view is already populated when the controller is instantiated (and subsequent hooks are called). - The correct DOM content is available when running the `$onChanges`, `$onInit`, `$doCheck` hooks. Previously, the "content children" were still present, not the "view children". - The same for pre-linking. - The template is compiled in the correct DOM context (e.g. has access to ancestors). Previously, it was compiled in isolation, inside a dummy element. For reference, here is the order of operations: **Before** 1. Compile template 2. Instantiate controller 3. Hook: $onChanges 4. Hook: $onInit 5. Hook: $doCheck 6. Pre-linking 7. Collect content children 8. Insert compiled template 9. Linking 10. Post-linking 11. Hook: $postLink **After** 1. Collect content children 2. Insert template 3. Compile template 4. Instantiate controller 5. Hook: $onChanges 6. Hook: $onInit 7. Hook: $doCheck 8. Pre-linking 9. Linking 10. Post-linking 11. Hook: $postLink Fixes #13912
…controller (angular#14289) Previously, the relative order of the AngularJS compiling/linking operations was not similar to AngularJS's, resulting in inconsistent behavior for upgraded components (which made upgrading to Angular less straight forward). This commit fixes it, by following the compiling/linking process of AngularJS more closely. Main differences: - The components view is already populated when the controller is instantiated (and subsequent hooks are called). - The correct DOM content is available when running the `$onChanges`, `$onInit`, `$doCheck` hooks. Previously, the "content children" were still present, not the "view children". - The same for pre-linking. - The template is compiled in the correct DOM context (e.g. has access to ancestors). Previously, it was compiled in isolation, inside a dummy element. For reference, here is the order of operations: **Before** 1. Compile template 2. Instantiate controller 3. Hook: $onChanges 4. Hook: $onInit 5. Hook: $doCheck 6. Pre-linking 7. Collect content children 8. Insert compiled template 9. Linking 10. Post-linking 11. Hook: $postLink **After** 1. Collect content children 2. Insert template 3. Compile template 4. Instantiate controller 5. Hook: $onChanges 6. Hook: $onInit 7. Hook: $doCheck 8. Pre-linking 9. Linking 10. Post-linking 11. Hook: $postLink Fixes angular#13912
…controller (angular#14289) Previously, the relative order of the AngularJS compiling/linking operations was not similar to AngularJS's, resulting in inconsistent behavior for upgraded components (which made upgrading to Angular less straight forward). This commit fixes it, by following the compiling/linking process of AngularJS more closely. Main differences: - The components view is already populated when the controller is instantiated (and subsequent hooks are called). - The correct DOM content is available when running the `$onChanges`, `$onInit`, `$doCheck` hooks. Previously, the "content children" were still present, not the "view children". - The same for pre-linking. - The template is compiled in the correct DOM context (e.g. has access to ancestors). Previously, it was compiled in isolation, inside a dummy element. For reference, here is the order of operations: **Before** 1. Compile template 2. Instantiate controller 3. Hook: $onChanges 4. Hook: $onInit 5. Hook: $doCheck 6. Pre-linking 7. Collect content children 8. Insert compiled template 9. Linking 10. Post-linking 11. Hook: $postLink **After** 1. Collect content children 2. Insert template 3. Compile template 4. Instantiate controller 5. Hook: $onChanges 6. Hook: $onInit 7. Hook: $doCheck 8. Pre-linking 9. Linking 10. Post-linking 11. Hook: $postLink Fixes angular#13912
…controller (angular#14289) Previously, the relative order of the AngularJS compiling/linking operations was not similar to AngularJS's, resulting in inconsistent behavior for upgraded components (which made upgrading to Angular less straight forward). This commit fixes it, by following the compiling/linking process of AngularJS more closely. Main differences: - The components view is already populated when the controller is instantiated (and subsequent hooks are called). - The correct DOM content is available when running the `$onChanges`, `$onInit`, `$doCheck` hooks. Previously, the "content children" were still present, not the "view children". - The same for pre-linking. - The template is compiled in the correct DOM context (e.g. has access to ancestors). Previously, it was compiled in isolation, inside a dummy element. For reference, here is the order of operations: **Before** 1. Compile template 2. Instantiate controller 3. Hook: $onChanges 4. Hook: $onInit 5. Hook: $doCheck 6. Pre-linking 7. Collect content children 8. Insert compiled template 9. Linking 10. Post-linking 11. Hook: $postLink **After** 1. Collect content children 2. Insert template 3. Compile template 4. Instantiate controller 5. Hook: $onChanges 6. Hook: $onInit 7. Hook: $doCheck 8. Pre-linking 9. Linking 10. Post-linking 11. Hook: $postLink Fixes angular#13912
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
I'm submitting a ... (check one with "x")
Current behavior
Trying to upgrade a ng1 component that uses inline templates and the $element service. The angular2 component will have NO children nodes.
Expected behavior
The child nodes should be available instantly (like in ng1)
Minimal reproduction of the problem with instructions
I'm running a ng1 app and use ngUpgrade to upgrade ng1 components to ng2 ones. The inline template is not instantly available.
MINIMAL DEMO
OUTPUT NG1
OUTPUT NG2
As you can see, the element is not available until the $timeout.
What is the motivation / use case for changing the behavior?
Gradually upgrade a ng1 application to ng2 instead of having to do a big bang
Please tell us about your environment:
Cordova android/ios/windows Phone hybrid angular 1 app trying to migrate to angular2
Using:
Typescript compiling to ES5
The text was updated successfully, but these errors were encountered: