感谢Angular 2页面上的"英雄之旅"教程,我设法创建了一个简单的Angular 2应用程序.然后使用Enitity Framework我决定创建一个数据库.并从中填充英雄列表(不是从文件中).我创建了Web Api Controller并添加了简单的get方法.然后在hero.service.ts我调用此方法以获取英雄列表.当我在我的应用程序午餐时,它会显示英雄列表,但没有任何值(名称和ID为空白).当我在浏览器中调试我的应用程序时,我可以看到this.heroes对象heroes.component.ts包含正确的数据.那么发生了什么?为什么不name和id展示?
hero.service.ts:
import {Injectable} from 'angular2/core';
import {HEROES} from './mock-heroes';
import {Hero} from './hero';
import {Http, Response} from 'angular2/http';
import 'rxjs/Rx';
import {Observable} from 'rxjs/Observable';
@Injectable()
export class HeroService {
public values: any;
constructor(public _http: Http) { }
private _heroesUrl = 'http://localhost:61553/api/values'; // URL to web api
getHeroes() {
return this._http.get(this._heroesUrl)
.map(res => <Hero[]>res.json())
.catch(this.handleError);
}
private handleError(error: Response) {
console.error(error);
return Observable.throw(error.json().error …Run Code Online (Sandbox Code Playgroud) 我的Microsoft.ApplicationInsights物体有问题。每次代码第一次碰到这些对象中的一个,初始化时间就非常长(有时甚至是40秒左右)。
范例1:
范例2:
如此长的首次加载的原因是什么?我怎样才能解决这个问题?