angular: language-service: Member (function) is not callable in ng-template

I’m submitting a … (check one with “x”)

[x] bug report => search github for a similar issue or PR before submitting
[ ] 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

As seen in demo for ngx-datatable project, this usage:

<ng-template let-column="column" let-sort="sortFn" ngx-datatable-header-template>
    <span (click)="sort()">{{column.name}}</span>
</ng-template>

Results in an error of:

Error:(32, 2) Angular: Member sort is not callable

Expected behavior

No error. sortFn is a callable function and the code does in fact work correctly.

Minimal reproduction of the problem with instructions

Run demo for ngx-datatable through the language-service.

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

I like my error console to be empty. Having to constantly mentally process and dismiss this error in the IDE is unproductive.

Please tell us about your environment:

IntelliJ IDEA 2017.1.1 Build #IU-171.4073.35, built on April 6, 2017 JRE: 1.8.0_112-release-736-b16 x86_64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o Mac OS X 10.12.4

  • Angular version: 4.0.3

  • Browser: N/A

  • Language: TypeScript 2.2.2

  • Node (for AoT issues): node --version = v7.9.0

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 45
  • Comments: 24 (2 by maintainers)

Commits related to this issue

Most upvoted comments

That’s caused by “Angular Language Service” plugin in VS-Code. Just uninstall it.

Until this gets somehow fixed, you can workaround this by creating a trigger method and use it like this:

<ng-template let-column="column" let-sort="sortFn" ngx-datatable-header-template>
    <span (click)="trigger(sort)">{{column.name}}</span>
</ng-template>

In component add the method:

@Component(...)... {
    ...
    trigger(callback, ...args) {
        return callback(...args);
    }
}

any updates?

I’ve got the same problem and found another workaround: use fn.call(thisArg, ...args)

<ng-template ng-label-tmp ng-label-tmp let-item="item" let-clear="clear">
    <span (click)="clear.call(undefined, item)">clear</span>
</ng-template>

I am still experiencing this error with language service 0.900.0 in combination with transloco, See for an example: https://github.com/ngneat/transloco/issues/177

Sorry it took so long, https://github.com/angular/angular/pull/33782 should fix this.

This workaround is working for me:

<ng-template let-column="column" let-sort="sortFn()" ngx-datatable-header-template>
    <span (click)="sort">{{column.name}}</span>
</ng-template>

By invoking the function inside the let- assignment instead of inside the (click) handler, you will avoid this bug and still get the same functionality.

The workaround that I use is this:

Instead of passing the highlight function directly, pass a fns object that has this content { highlight: highlight }

And use it like this with no errors:

<ng-template let-item="item" let-fns="fns">
  <span (click)="fns.highlight(item)">{{item.name}}</span>
</ng-template>

Another workaround is proposed here: https://github.com/angular/vscode-ng-language-service/issues/234#issuecomment-385955606 I haven’t tried it myself, but it makes sense.

Same here, using VSCode.

Same happening here, using Angular 5.2.8.

Any progress on this issue ?

@chuckjaz any updates on this?

Same here, Angular 5.2.9 and ng-bootstrap 1.0.4. ng build --prod works fine and my app also works. Not sure why the intellisence complains. Any progress on this issue?