My goal is to retrieve data from my Parse Server where MongoDB is installed.
Although I have successfully displayed the data in the console, I am facing issues interpolating them in the HTML template.
Here is my search.ts file:
import { localData } from './../../services/local';
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Parse } from 'parse';
import 'rxjs/add/operator/map';
import {User} from '../../models/User';
@Component({
selector: 'page-search',
templateUrl: 'search.html'
})
export class SearchPage {
currentUser = Parse.User.current();
query1 = new Parse.Query('Friends');
friendQuery = new Parse.Query('Friends');
query = new Parse.Query(Parse.User);
tmp: any;
users: any= [];
user: any= [];
loadUsers (){
this.tmp = this.localdata.getUsers();
}
initializeItems() {
this.users;
}
constructor(public navCtrl: NavController, private localdata: localData) {
this.query.find().then(data => {
this.tmp = data;
console.log(this.tmp);
this.localdata.setUsers(this.tmp);
this.users = this.localdata.getUsers();
console.log (this.users);
console.log(this.users.username)
})
}
getItems(ev: any) {
// Reset items back to all of the items
this.initializeItems();
// set val to the value of the searchbar
let val = ev.target.value;
// if the value is an empty string don't filter the items
if (val && val.trim() != '') {
this.users = this.users.filter((user) => {
return (user.username.toLowerCase().indexOf(val.toLowerCase()) > -1);
})
}
}
}
This is the local.ts file where I save the array of Users
import { Component } from '@angular/core';
export class localData {
setUsers (users){
window.localStorage.users_data = JSON.stringify(users);
}
getUsers(){
return JSON.parse(window.localStorage.users_data || '[]');
}
}
And finally, here is my HTML template search.html:
<ion-header>
<ion-navbar>
<ion-searchbar
(ionInput)="getItems($event)"
(ionCancel)="onCancel($event)"
[animated]= true>
</ion-searchbar>
</ion-navbar>
</ion-header>
<ion-content padding>
<ion-item class="item-avatar item-avatar-left item-button-right common-list" *ngFor="let user of users"></ion-item>
<div></div>
</ion-content>
In the HTML template, inside the div, I am trying to use user.username but it is not working as expected.
Can someone please advise me on how to display it correctly?
Thank you so much!