I have the following code working in browser, but upon testing on simulator or device the list view of cards does not immediately appear once location has been obtained. If I tap (only works on device) on the search then the list will suddenly show.
What if anything am I doing wrong?
import {Component, Pipe, PipeTransform} from '@angular/core';
import {DomSanitizationService} from '@angular/platform-browser';
import {NavController, Platform} from 'ionic-angular';
import {MovieService} from '../services/MovieService';
import {MovieInfo} from '../movie-info/movie-info';
@Pipe({name: 'safe'})
export class Safe {
constructor(private sanitizer:DomSanitizationService){}
transform(html) {
return this.sanitizer.bypassSecurityTrustStyle(html);
}
}
@Component({
templateUrl: 'build/pages/movie-list/movie-list.html',
providers: [MovieService],
pipes: [Safe]
})
export class MovieListPage {
movies: Array<any>;
constructor(private navController: NavController, private movieService: MovieService, private platform: Platform) {
this.loadGeoData();
}
searchMovieDB(event, key) {
if(event.target.value.length > 2) {
this.movieService.searchMovies(event.target.value).subscribe(
data => {
this.movies = data.results;
console.log(data);
},
err => {
console.log(err);
},
() => console.log('Movie Search Complete')
);
}
}
itemTapped(event, movie) {
console.log(movie);
this.navController.push(MovieInfo, {
movie: movie
});
}
loadGeoData() {
this.platform.ready().then(() => {
let options = {timeout: 10000, enableHighAccuracy: true};
navigator.geolocation.getCurrentPosition(
(position) => {
this.movieService.searchMovies(position.coords.latitude+','+position.coords.longitude).subscribe(
data => {
this.movies = data.results;
console.log(data);
},
err => {
console.log(err);
},
() => console.log('Movie Search Complete')
);
},
(error) => {
console.log(error);
}, options
);
});
}
}
With the following template:
<ion-header>
<ion-navbar>
<ion-title>
Movie List
</ion-title>
</ion-navbar>
</ion-header>
<ion-content class="home" padding>
<ion-item>
<ion-input type="text" placeholder="Search a movie..." (input)="searchMovieDB($event, searchKey)"></ion-input>
</ion-item>
<ion-list>
<ion-card *ngFor="let movie of movies" (click)="itemTapped($event, movie)">
<img src="{{movie.image}}"/>
<ion-card-content>
<ion-card-title>
{{movie.title}}
</ion-card-title>
<div [innerHTML]="movie.excerpt"></div>
</ion-card-content>
</ion-card>
</ion-list>
</ion-content>
Also, currently have lots of:
"WARNING: sanitizing HTML stripped some content."
I tried using the "safe" pipe in the code above but that results in an exception error on build in the browser_adapter.js file.