I have tried using custom pipe.This is my pipe file
import { Pipe, PipeTransform } from '@angular/core';
import { User } from 'src/app/user';
import { ApiService } from 'src/app/api.service';
import { Observable } from 'rxjs';
import { isNgTemplate } from '@angular/compiler';
import { map } from 'rxjs/operators';
@Pipe({
name: 'my-pipe'
})
export class MyPipePipe implements PipeTransform {
isEqual = false;
api: ApiService;
transform(post_id: number, users: Observable< User[]> ): any {
// users = this.api.getUserList();
users.subscribe(user => user.filter(userss => {
if (userss.id === post_id && post_id !== null) { this.isEqual = true; } else {
console.log(this.isEqual + ' ' + ' hataa');
}
}));
}
All i want is nonexistent users cant post.Therefore i trying user's id equalize with post's userId.Here is my html code
<div class="form-group">
<label for="userId">User Id</label>
<input type="number" class="form-control" id ="userId" name="userId" required [(ngModel)]="posts.userId">
<!--<div class="tetx text-danger" *ngIf="!isEqual" >Invalid Id!!!</div>-->
<div *ngIf=" my-pipe: posts.userId " >
Invalidd
</div>
</div>
But unfortunately I get this error:
[Angular] TypeError: Cannot read property 'toUpperCase' of undefined