I currently have this:
<div *ngIf="name !== '@name1'>
  Show something
</div>
But I would like to change it to check if var name value starts with a specific character for example @.
How can I do this?
I currently have this:
<div *ngIf="name !== '@name1'>
  Show something
</div>
But I would like to change it to check if var name value starts with a specific character for example @.
How can I do this?
 
    
     
    
    Use startsWith method like this
<div *ngIf="name.startsWith('@')">
  Show something
</div>
And if you want to check if string doesn't start with '@' simply add '!' like *ngIf="!name.startsWith('@')"
 
    
    You can simply use indexOf method to get starting index of your character and if it's 0 it means it's true else false.
Like below.
<div *ngIf="name.indexOf('@name1') === 0">
   it's start with @name1
</div>
<div *ngIf="name.indexOf('@name1') !== 0">
  it's not start with @name1
</div>
 
    
    you can just add this code inside the Component :
export class NameComponent implements OnInit {
public isNameContainAt = false;
public name = 'name';
constructor() { }
ngOnInit() {
if (this.name.startsWith('@') == true) {
  this.isNameContainAt = true;
}
}
}
And then in the template :
<div *ngIf="!isNameContainAt">
Show something
