我正在为LG smartTV(WebOS)开发应用程序并使用Angular2。在Chrome和Firefox中,一切正常,但在电视嵌入式浏览器中我遇到了问题。这个问题只在我使用HTTP模块和Promises时才会重现。 请帮助理解是什么原因。
来自控制台的错误: errors from console
service.ts
import { Injectable } from '@angular/core';
import { News } from "../entity/news";
import {Http, Headers, Response} from '@angular/http';
import 'rxjs/add/operator/toPromise';
import {Observable} from 'rxjs/Rx';
import 'rxjs/add/operator/map';
@Injectable()
export class NewsService {
private apiUrl = 'api_url';
constructor(private http: Http) {
}
getNews(): Promise<News[]> {
return this.http.get(this.apiUrl)
.toPromise()
.then(response => response.json()[1].newsList as News[])
.catch(this.handleError);
}
private handleError(error: any): Promise<any> {
console.error('An error occurred', error);
return Promise.reject(error.message || error);
}
}
home.component.ts
import { Component } from '@angular/core';
import { NewsService } from '../services/app.news.service';
import { News } from "../entity/news";
@Component({
selector: 'home',
providers: [],
styleUrls: [ './home.style.scss' ],
templateUrl: './home.template.html'
})
export class Home {
news: News[];
constructor(
public newsService: NewsService) {
}
ngOnInit() {
this.newsService.getNews()
.then(news => this.news = news);
}
}