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.

Language Service doesn't support directive composition API

See original GitHub issue

Which @angular/* package(s) are the source of the bug?

language-service

Is this a regression?

No

Description

Let say I have a directive like this:

import { Directive, HostBinding, Input } from '@angular/core';

@Directive({
  standalone: true,
  selector: '[appBgColor]'
})
export class BgColorDirective {
  @HostBinding('style.display') display = 'inline-block';
  @Input() @HostBinding('style.background-color') bgColor = 'yellow';
}

In the component, I want to use directive composition API including the inputs

import { Component } from '@angular/core';
import { BgColorDirective } from '../bg-color.directive';

@Component({
  selector: 'app-my-comp',
  templateUrl: './my-comp.component.html',
  styleUrls: ['./my-comp.component.scss'],
  hostDirectives: [
    {
      directive: BgColorDirective,
      inputs: ['bgColor']
    }
  ]
})
export class MyCompComponent { }

And the usage of component

<app-my-comp [bgColor]="'red'"></app-my-comp>

After compile, it works fine. But in VSCode, I got this error:

image

I think this is about the language service issue.

Please provide a link to a minimal reproduction of the bug

https://github.com/wellwind/ng-directive-composition-api-language-service-bug-demo

Please provide the exception or error you saw

It should has no error in VSCode.

Please provide the environment you discovered this bug in (run ng version)

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 15.0.0
Node: 16.17.0
Package Manager: npm 8.15.0
OS: darwin arm64

Angular: 15.0.0
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1500.0
@angular-devkit/build-angular   15.0.0
@angular-devkit/core            15.0.0
@angular-devkit/schematics      15.0.0
@schematics/angular             15.0.0
rxjs                            7.5.7
typescript                      4.8.4

Anything else?

No response

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
atscottcommented, Nov 17, 2022

Are you using the latest version of the extension? The latest version of the extension is required because it bundles the Angular compiler and host directives were not supported pre-v15.

Note: I downloaded your project everything appeared to be working.

0reactions
angular-automatic-lock-bot[bot]commented, Dec 23, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Directive composition API - Angular
The directive composition API lets you apply directives to a component's host element from within the component TypeScript class.
Read more >
Variables created in the template always have type any #1155
The types shown by Angular Language Service reflect what you've ... Typechecking of context doesn't work with custom directives #1158.
Read more >
Introduction to Angular Language Service | by Enea Jahollari
A language service is a program that you feed your code, and it will report you… ... So, we won't get any support...
Read more >
Angular Language Service not working with VS Code ...
4 Answers 4 · Go to the extensions tab on VS Code · Click the gear icon on the right side of the...
Read more >
Composition API FAQ - Vue.js
Composition API is a set of APIs that allows us to author Vue components using ... on function composition, Composition API is NOT...
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