繁体   English   中英

Angular 2 http.get

[英]Angular 2 http.get

我正在做以下内容进入Angular 2并且我得到一个运行时异常:

http.get('http://localhost/MyCart/Home/GetProducts').subscribe(result => {
    this.categories = result.json().Data as any[];
    this.LoadDictionary();
    window.console.log(this.categories);
});

这是正确的语法吗? 我究竟做错了什么? 如果我删除http.get,应用程序就可以了。

编辑:

错误如下。 请记住,我正在使用Angular的.NET Core模板。

处理请求时发生未处理的异常。 例外:调用节点模块失败,错误:ReferenceError:窗口未在C:\\ Users \\ samir \\ Desktop \\ angular-core new \\ ClientApp \\ dist \\ main-server.js:269:13在SafeSubscriber.schedulerFn中定义[as _next](C:\\ Users \\ samir \\ Desktop \\ angular-core new \\ ClientApp \\ dist \\ vendor.js:3774:40)at SafeSubscriber.module.exports.SafeSubscriber .__ tryOrUnsub(C:\\ Users \\ samir \\ Desktop \\ angular -core new \\ ClientApp \\ dist \\ vendor.js:23052:16)在SafeSubscriber.module.exports.SafeSubscriber.next(C:\\ Users \\ samir \\ Desktop \\ angular-core new \\ ClientApp \\ dist \\ vendor.js:23001) :22)在Subscriber.module.exports.Subscriber.next上的Subscriber.module.exports.Subscriber._next(C:\\ Users \\ samir \\ Desktop \\ angular-core new \\ ClientApp \\ dist \\ vendor.js:22943:26) (C:\\ Users \\ samir \\ Desktop \\ angular-core new \\ ClientApp \\ dist \\ vendor.js:22907:18)在EventEmitter.module.exports.Subject.next(C:\\ Users \\ samir \\ Desktop \\ angular-core)在Object.next的新\\ ClientApp \\ dist \\ vendor.js:68525:25)(C:\\ Users \\ samir \\ Desktop \\ angular-core new \\ ClientApp \\ dist \\ vendor.js:90000: 21)在SafeSubscriber.chedulerFn [as _next](C:\\ Users \\ samir \\ Desktop \\ angular-core new \\ ClientApp \\ dist \\ vendor.js:3762:56)的SafeSubscriber.module.exports.SafeSubscriber .__ tryOrUnsub(C: \\ Users \\ samir \\ Desktop \\ angular-core new \\ ClientApp \\ dist \\ vendor.js:23052:16)at SafeSubscriber.module.exports.SafeSubscriber.next(C:\\ Users \\ samir \\ Desktop \\ angular-core new \\ ClientApp订阅服务器上的Subscriber.module.exports.Subscriber._next(C:\\ Users \\ samir \\ Desktop \\ angular-core new \\ ClientApp \\ dist \\ vendor.js:22943:26)中的\\ dist \\ vendor.js:23001:22)在EventEmitter.module.exports.Subject.next(C:\\ Users)中的.module.exports.Subscriber.next(C:\\ Users \\ samir \\ Desktop \\ angular-core new \\ ClientApp \\ dist \\ vendor.js:22907:18) \\ samir \\ Desktop \\ angular-core new \\ ClientApp \\ dist \\ vendor.js:68525:25)at Object.next(C:\\ Users \\ samir \\ Desktop \\ angular-core new \\ ClientApp \\ dist \\ vendor.js:90000 :21)

window.console.log(this.categories);

应该

console.log(this.categories);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM