Skip to content
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

Unknown method .bind #93

Closed
YogliB opened this issue May 9, 2017 · 41 comments
Closed

Unknown method .bind #93

YogliB opened this issue May 9, 2017 · 41 comments
Labels

Comments

@YogliB
Copy link

YogliB commented May 9, 2017

I'm using VS Code v1.12.1, and Angular Language Service v0.1.3, with an Ionic 3 project, and I get these warnings, despite everything being fine...

@bkbonner
Copy link

I just saw this with Angular Language Service and VS Code 1.13. happens in Heroes Tutorial when adding (save()) method to hero-detail-component.html

Code functions fine, but shows red squiggly lines even though method is clearly there.

@chuckjaz
Copy link
Contributor

@bkbonner I cannot reproduce this with https://angular.io/generated/zips/toh-pt6/toh-pt6.zip Do you have a modification to this that shows this issue.

@bkbonner
Copy link

I can try to send my codebase. Let me see if there is something else different in i you're that lets it work.

@bkbonner
Copy link

Hi @chuckjaz . So if I go and modify the .ts file and remove the save() method and then go to the corresponding html file and modify the method name call in the html file, it underlines it. If I add the method back on the .ts side, and go back to the .html file, the squiggly line stays until I click ctrl+space and select one of the method options in the drop-down.

I'm not sure if this is how it was behaving before, but maybe it's how the validation of the method's existence is being triggered that is causing the confusing result.

@bkbonner
Copy link

I included a video to show how it looks: https://youtu.be/UjfFprgvTQg no audio, but I included closed captions to describe it.

@karocksjoelee
Copy link

I am facing same problem as well ...

@Kyderman
Copy link

Kyderman commented Mar 5, 2018

I have the same problem using .bind in a template.

It works but we get errors.

@spacedawwwg
Copy link

+1 same issue here

@CaffGeek
Copy link

Any solution yet?

@JorgeSanchezGr
Copy link

+1 here too!

@Luchnik
Copy link

Luchnik commented Apr 14, 2018

+1 exact same issue. Any updates?

@RafaelKr
Copy link

RafaelKr commented May 7, 2018

Same error with .bind(this) here.

@shamilovtim
Copy link

Confirmed still happening in VS Code with angular language service. Ionic 3, Angular 5.

@AndrWeisR
Copy link

AndrWeisR commented Jun 22, 2018

Also happening with 'hasError' in extension 0.1.9 in VS Code 1.24.1:

<div *ngIf="form.get('phone').hasError(validation.type)">

complains that hasError is not a function, although it is (in the AbstractControl class of Angular forms).

Edit: although this can be fixed by adding a "!" thus:
<div *ngIf="form.get('phone')!.hasError(validation.type)">

That's because the get method returns AbstractControl or null. I presume the language service is complaining that 'hasError' is not a function of 'null'. It would be clearer if the error was:
The expression might be null
as it is for other functions, e.g. <div *ngIf="form.get('phone').errors[validation.type]">
produces the error The expression might be null.

@aj-r
Copy link

aj-r commented Jul 5, 2018

Also happening with $any(), which should always exist (https://angular.io/guide/aot-compiler#disabling-type-checking-using-any)

ex)

<input [(ngModel)]="$any(content).houseId" />
[Angular] Unknown method '$any'

@JosepAlacid
Copy link

Same issue here Ionic3 Angular5

@joseluisq
Copy link

I got the same error in VS Code v1.25.1 + Angular v6.0.1

@1011178l
Copy link

Got the same error in VS code 1.25.1

Version: 1.25.1
Commit: 1dfc5e557209371715f655691b1235b6b26a06be
Date: 2018-07-11T15:40:20.190Z
Electron: 1.7.12
Chrome: 58.0.3029.110
Node.js: 7.9.0
V8: 5.8.283.38
Architecture: x64

@pgwest
Copy link

pgwest commented Aug 16, 2018

Same error in Angular 5 and VS Code 1.26.0

@MarkvanTurnhout
Copy link

I have the same problem in Angular 6.

[displayWith]="displayFn.bind(this)"

Everything works fine and I see no errors while running, just in the editor:

[Angular] Unknown method 'bind'

@Spaier
Copy link

Spaier commented Jan 21, 2019

The same happens to me.

[myFun]="myService.myFunc.bind(myService)"

@eugensunic
Copy link

Is there any way to surpress this warning instead of everyone saying I have the same problem?

@multilexus
Copy link

try adding a semicolon after function name like this

<ion-button (click)="test();">
Test Button

This seems to remove the warning.

@YogliB
Copy link
Author

YogliB commented Feb 17, 2019

Honestly, I have no idea if this is still an issue.
VS Code & the ALS have been updated a lot since then, and I haven't seen this warning in a long time...

@RafaelKr
Copy link

Yes, this is still an issue.
image

VS Code About:

Version: 1.31.1
Commit: 1b8e8302e405050205e69b59abb3559592bb9e60
Date: 2019-02-12T02:19:29.629Z
Electron: 3.1.2
Chrome: 66.0.3359.181
Node.js: 10.2.0
V8: 6.6.346.32
OS: Linux x64 4.15.0-45-generic

@multilexus
Copy link

multilexus commented Feb 18, 2019 via email

@RafaelKr
Copy link

@multilexus this is not working.

@anonymuos1
Copy link

Yes, this is still an issue.
image

VS Code About:

Version: 1.31.1
Commit: 1b8e8302e405050205e69b59abb3559592bb9e60
Date: 2019-02-12T02:19:29.629Z
Electron: 3.1.2
Chrome: 66.0.3359.181
Node.js: 10.2.0
V8: 6.6.346.32
OS: Linux x64 4.15.0-45-generic

Same problem here :-/ Any solution?

@ace90210
Copy link

ace90210 commented Feb 22, 2019

+1 with angular 7 displayWith on a mat-autocomplete
image

Works fine but warnings

@LMariano
Copy link

@multilexus is right i'm working with Angular 7 in VS code 1.31.1

@mspoerry
Copy link

mspoerry commented Apr 9, 2019

It is still a problem. Any news?

@AakashCodeLab
Copy link

AakashCodeLab commented Apr 23, 2019

The same happens to me.

[myFun]="myService.myFunc.bind(myService)"

write like this:--
[myFun]='handleFun'
---in html

this.handleFun=this.myService.myFunc.bind(myService);
--in ts file

@AakashCodeLab
Copy link

AakashCodeLab commented Apr 23, 2019

Yes, this is still an issue.
image
VS Code About:

Version: 1.31.1
Commit: 1b8e8302e405050205e69b59abb3559592bb9e60
Date: 2019-02-12T02:19:29.629Z
Electron: 3.1.2
Chrome: 66.0.3359.181
Node.js: 10.2.0
V8: 6.6.346.32
OS: Linux x64 4.15.0-45-generic

Same problem here :-/ Any solution?

write like this:--
(click)='handleFun'
---in html

this.handleFun=this.setLanguage.bind(this,language);
--in ts file

@AakashCodeLab
Copy link

+1 with angular 7 displayWith on a mat-autocomplete
image

Works fine but warnings

write like this:--
[displayWith]='displayFun'
---in html

this.displayFun=this.displayFun.bind(this);
--in ts file

@gshokanov
Copy link

Encountered this bug when using $any() method in <ng-template> in Angular 7.

@lonix1
Copy link

lonix1 commented Jun 5, 2019

Still complaining for hasError in

<div *ngIf="form.get('phone').hasError(validation.type)">

VSCode 1.34.0
extension 0.800.0

@klenium
Copy link

klenium commented Oct 6, 2019

Until they fix it, there's a workaround (at least for myMethod.bind(this):

bindMyMethodWithThis() {
    return this.myMethod.bind(this);
}

<MyComponent [myInput]="bindMyMethodWithThis()">

@andrius-pra
Copy link
Collaborator

Until they fix it, there's a workaround (at least for myMethod.bind(this):

bindMyMethodWithThis() {
    return this.myMethod.bind(this);
}

<MyComponent [myInput]="bindMyMethodWithThis()">

It's a bad idea to use bind function inside template. bind function creates a new function on every call. So you will create a new function on every change detection. it's better to assign arrow function to class property:

myMethod = (param1: any, param2: any) => {
   // method logic
}
<MyComponent [myInput]="myMethod">

@klenium
Copy link

klenium commented Oct 6, 2019

@andrius-pra Nice idea, I'll now use this, thanks.

@kyliau kyliau changed the title "[Angular] Unknown method..." warnings Unknown method .bind Nov 25, 2019
kyliau added a commit to kyliau/angular that referenced this issue Nov 25, 2019
When performing diagnostic checks or completions, we should take into
account members and properties in the base class, if any. Otherwise, the
language service will produce a false error.

PR closes angular/vscode-ng-language-service#93
@kyliau
Copy link
Contributor

kyliau commented Nov 25, 2019

Sorry everyone that it took so long for us to address this issue. The PR above should fix it.

kyliau added a commit to kyliau/angular that referenced this issue Nov 26, 2019
…r#34041)

When performing diagnostic checks or completions, we should take into
account members and properties in the base class, if any. Otherwise, the
language service will produce a false error.

PR closes angular/vscode-ng-language-service#93

PR Close angular#34041

(cherry picked from commit 7cd16b9)
kyliau added a commit to kyliau/angular that referenced this issue Nov 26, 2019
…r#34041)

When performing diagnostic checks or completions, we should take into
account members and properties in the base class, if any. Otherwise, the
language service will produce a false error.

PR closes angular/vscode-ng-language-service#93

PR Close angular#34041

(cherry picked from commit 7cd16b9)
matsko pushed a commit to angular/angular that referenced this issue Nov 26, 2019
#34046)

When performing diagnostic checks or completions, we should take into
account members and properties in the base class, if any. Otherwise, the
language service will produce a false error.

PR closes angular/vscode-ng-language-service#93

PR Close #34041

(cherry picked from commit 7cd16b9)

PR Close #34046
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Feb 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.