question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The template context does not define a member called 'item'

See original GitHub issue

Describe the bug

Not sure if this issue is related to this extension, but the code does compile and work even if the language service gives me an error in the console.

In a component.html file I have this:

<ng-template ng-label-tmp ng-option-tmp let-item="item">
    {{ item.name }} -- {{ item.description }} -- {{ item.price | currency }}
</ng-template>

the let-item="item" piece is red highlighted and this is the description:

The template context does not define a member called ‘item’

To Reproduce Use any *-tmp directives along with let-* ones.

Expected behavior No Errors should be highlighted for the let-item="item" directive.

Logs

  1. Console output
[Info  - 17:40:22] Angular language server process ID: 21305
[Info  - 17:40:22] Using typescript v3.7.4 from /home/user/.vscode/extensions/angular.ng-template-0.900.5/node_modules/typescript/lib/tsserverlibrary.js
[Info  - 17:40:24] Using @angular/language-service v9.0.0-rc.9 from /home/user/.vscode/extensions/angular.ng-template-0.900.5/server/node_modules/@angular/language-service/bundles/language-service.umd.js
[Info  - 17:40:25] Log file: /home/user/.config/Code/logs/20200123T153034/exthost9/Angular.ng-template/nglangsvc.log
[Error - 17:40:39] No config file for /home/user/git/projects/my-app/src/app/ui-widgets/app-card/add-item-card/add-item-card.component.html
  1. Log file nglangsvc.log

Additional context If I remove both ng-label-tmp and ng-option-tmp directives the error disappears.

UPDATE Downgrading the extension to v0.900.4 the message error disappears. The v0.900.5 starts to show this error.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:17 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
ayazhafizcommented, Jan 29, 2020

@fdinardo okay, the PR above (https://github.com/angular/angular/pull/35036) will make this a warning 🙂

4reactions
kyliaucommented, Jan 24, 2020

When diagnostics are performed in the language service, the context for the embedded view is assumed to be the context of the structural directive that is applied to ng-template. This assumption is incorrect, according to the docs in angular.io:

Angular automatically expands the shorthand syntax as it compiles the template. The context for each embedded view is logically merged to the current component context according to its lexical position.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ng-template Error: The template context does not define a ...
So Visual Studio Code gives me the error for the 3 parameters of the ng-template . However, when compiled the placeholder does show...
Read more >
The "The template context of 'DxTemplateDirective' does not ...
The "The template context of 'DxTemplateDirective' does not define an implicit value" error occurs in an Angular project.
Read more >
Template context of 'DataTableColumnCellDirective' does not ...
Hello, I am getting an error with the ng-template element, ... of 'DataTableColumnCellDirective' does not define a member called 'row' #860 ...
Read more >
Chapter 4, Understanding and Using Angular Components
Again, just like templates, Angular will not pull in these styles at runtime, ... Thus, any element that adds the name class to...
Read more >
NgTemplateOutlet - Angular
Using the key $implicit in the context object will set its value as default. @Input() ngTemplateOutlet: TemplateRef<any> | null. A string defining the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found