0
我在浏览器没有发出HTTP呼叫的打字稿中有角2问题。浏览器中的网络部分没有看到任何HTTp调用。 角码的作品,当我没有任何HTTP服务的服务,它带来的数据,当我使用HTTP它doenst作出任何http请求角2没有从浏览器发出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)
}
};
我有类似的问题。我在我的asp核心应用程序中设置了cors,我用postman调用了url,它给了我一个json。当我尝试从服务中调用时,它什么也不返回。我试着用你的代码,它只显示'等待'。 http://stackoverflow.com/questions/40030613/asp-net-core-api-cors-for-angular2-app – FacundoGFlores