Expected the operants to be of similar type or any Angular

Viewed 11166

I got this issue where i cannot find the solutionenter image description here

As I saw router: Router and router.url: string. So I can't find any explanation why it's complaining in html when router.url === '/successlogin'. Any idea?

Update: I changed type of router, router.url: String and it's ok now but I think it should work the opposite. Why is this happening? Until now I thought type string was the "right" one and not String...

My code simplified:

HTML

<div *ngIf="!global.showUnauthorizedMessage || router.url === '/successlogin'" class="beforeFooter"></div>
 <div *ngIf="!global.showUnauthorizedMessage || router.url ==='/successlogin'" id="footer">

Component

import { Router } from '@angular/router';
constructor( public router: Router) { code here }
4 Answers

This message is from the "Angular Language Service" extension in VSCode !

Probably an update because before I didn't have this message....

2 solutions I found is to use localeCompare() like this:

router.url.localeCompare('/successLogin')===0

or

use String instead of string

Quick fix for this :

a) store"/successlogin" in some variable and do comparison with that variable

Component

import { Router } from '@angular/router';

export class someComponent {

successLogin = '/successlogin'; 

constructor( public router: Router) { code here }
}

Html

<div *ngIf="!global.showUnauthorizedMessage || router.url === successLogin" class="beforeFooter"></div>
 <div *ngIf="!global.showUnauthorizedMessage || router.url === successLogin" id="footer">

Note since this seems to be a path, ideally it should be read from a constant file, for maintainability perspective.

Cheers (y)

Had the same issue. I changed the type from String to string and the error went away.

some times it comes from using;

*ngIf="!somevalvar === somevar"

instead use :

*ngIf="somevalvar !== somevar"
Related