Angular 2 没有从浏览器进行 http 调用

Angular 2 is not making http call from browser

我在 angular 2 的打字稿中遇到问题,浏览器没有进行 HTTP 调用。我在浏览器的网络部分看不到任何 HTTp 调用。 angular 代码在我没有任何 http 服务时工作,当我使用 HTTP 时它会带来数据,它不会发出任何 http 请求

以下是我的代码。

<script src="~/lib/es6-shim.min.js"></script>
<script src="~/lib/system-polyfills.js"></script>
<script src="~/lib/shims_for_IE.js"></script>

<script src="~/lib/angular2-polyfills.js"></script>
<script src="~/lib/system.js"></script>
<script src="~/lib/Rx.js"></script>
<script src="~/lib/angular2.dev.js"></script>
<script src="~/lib/http.dev.js"></script>
<script src="~/lib/router.dev.js"></script>

服务:

    import {Injectable} from 'angular2/core';
import {Http, Response} from 'angular2/http';
import {Observable}     from 'rxjs/Observable';

@Injectable()
export class AuthService {

    private _authPath = 'http://api/Auth';
    constructor(private http: Http) { }
    getAuthSettings() {

        return new Promise((resolve, reject) => {

            return this.http.get(this._authPath).toPromise().then((val: Response) => resolve(val.text()));

        });
    }
    private handleError(error: Response) {
        // in a real world app, we may send the error to some remote logging infrastructure
        // instead of just logging it to the console
        console.error(error);
        return Observable.throw(error.json().error || 'Server error');
    }

}

主要模块 :

    import { Component } from 'angular2/core';
import {AuthService} from './auth.service';
import {OnInit} from 'angular2/core';
import {HTTP_PROVIDERS} from 'angular2/http';

@Component({

    selector: "main-app",
    template: "{{title}}",
    providers: [HTTP_PROVIDERS, AuthService]

})
export class AppComponent implements OnInit {
    public title: string = '';
    constructor(private _authService: AuthService) {
    }
    ngOnInit() {
        //this.title = "aaa";
        this._authService.getAuthSettings().then((val: string) => {
            this.title = val;

        });
        //this._authService.getAuthSettings().subscribe((val: string) => this.title = val)
    }

};

I dont see any HTTP call in network section in browser.

可能有一些过滤器阻止您看到它。为确保更新代码如下:

 console.log('starting');
 this._authService.getAuthSettings()
     .then((val: string) => {
        this.title = val;
        console.log('success');
     },() => console.log('fail'));
 console.log('waiting');

并查看发生了哪些日志。希望它有所帮助。抱歉,如果没有