Skip to content

TemplateRef shares context between instances when none is provided #10045

Closed

Description

@justindoherty

I'm submitting a ... (check one with "x")

[x] bug report
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior
angular/modules/@angular/core/src/linker/template_ref.ts currently uses a single object for EMPTY_CONTEXT. The problem is when ViewContainerRef #createEmbededView is called without providing a context object the shared one is used causing pollution between all instances utilizing the context.

Expected/desired behavior
Object sharing doesn't happen between instances relying on the context.

Maybe some solutions could be:

  • TemplateRef_<C> instantiates a new object when none is provided
  • ViewContainerRef #createEmbededView makes context mandatory and TemplateRef_<C> stops checking isBlank of context.

Reproduction of the problem
If the current behavior is a bug or you can illustrate your feature request better with an example, please provide the steps to reproduce and if possible a minimal demo of the problem via https://plnkr.co or similar (you can use this template as a starting point: http://plnkr.co/edit/tpl:AvJOMERrnz94ekVua0u5).

https://plnkr.co/edit/UhGsjLaHxiwI0n0nTYtN?p=preview
//TypeError: Cannot read property 'name' of undefined on second instance

Simplified Plunk: http://plnkr.co/edit/CQQembTFT0nOxGwCzSgc?p=preview
You can see the sharing of the context, test2 is listed twice in first block

What is the expected behavior?
No sharing of the context between instances

What is the motivation / use case for changing the behavior?
Errors

Please tell us about your environment:

  • Angular version: 2.0.0-rc.4
  • Browser: [all]
  • Language: [TypeScript 1.8.10]

Activity

  1. vicb commented on Jul 14, 2016

    @vicb
    Contributor

    Please try to simplify your plunker with the minimal amount of code required to reproduce the issue.

  2. justindoherty commented on Jul 15, 2016

    @justindoherty
    Author

    Here's the new plunk, I hope it's simplified enough.

    http://plnkr.co/edit/CQQembTFT0nOxGwCzSgc?p=preview

  3. added a commit that references this issue on Aug 8, 2016
    46bbcef
  4. angular-automatic-lock-bot commented on Sep 9, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  5. locked and limited conversation to collaborators on Sep 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions