我在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) 在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(C:\ Users \ samir \ Desktop \ angular-core new \ ClientApp \ dist \ vendor.js:22943:26) 在Subscriber.module.exports.Subscriber.next(C:\ Users \ samir \ Desktop \ angular-core new \ ClientApp \ dist \ vendor.js:22907:18) 在EventEmitter.module.exports.Subject.next(C:\ Users \ samir \ Desktop \ angular-core new \ ClientApp \ dist \ vendor.js:68525:25) 在Object.next(C:\ Users \ samir \ Desktop \ angular-core new \ ClientApp \ dist \ vendor.js:90000:21) 在SafeSubscriber.schedulerFn [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) 在SafeSubscriber.module.exports.SafeSubscriber.next(C:\ Users \ samir \ Desktop \ angular-core new \ ClientApp \ dist \ vendor.js:23001:22) 在Subscriber.module.exports.Subscriber._next(C:\ Users \ samir \ Desktop \ angular-core new \ ClientApp \ dist \ vendor.js:22943:26) 在Subscriber.module.exports.Subscriber.next(C:\ Users \ samir \ Desktop \ angular-core new \ ClientApp \ dist \ vendor.js:22907:18) 在EventEmitter.module.exports.Subject.next(C:\ Users \ samir \ Desktop \ angular-core new \ ClientApp \ dist \ vendor.js:68525:25) 在Object.next(C:\ Users \ samir \ Desktop \ angular-core new \ ClientApp \ dist \ vendor.js:90000:21)
答案 0 :(得分:3)
window.console.log(this.categories);
应该是
console.log(this.categories);