简体   繁体   中英

Angular 2 http.get

I am doing the following get in Angular 2 and I am getting a runtime exception:

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

Is that the correct syntax? What am I doing wrong? If I delete the http.get, application is fine.

EDIT:

The error is below. Keep in mind I am using Angular's SPA template for .NET Core.

An unhandled exception occurred while processing the request. Exception: Call to Node module failed with error: ReferenceError: window is not defined at C:\\Users\\samir\\Desktop\\angular-core new\\ClientApp\\dist\\main-server.js:269:13 at 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) at SafeSubscriber.module.exports.SafeSubscriber.next (C:\\Users\\samir\\Desktop\\angular-core new\\ClientApp\\dist\\vendor.js:23001:22) at Subscriber.module.exports.Subscriber._next (C:\\Users\\samir\\Desktop\\angular-core new\\ClientApp\\dist\\vendor.js:22943:26) at Subscriber.module.exports.Subscriber.next (C:\\Users\\samir\\Desktop\\angular-core new\\ClientApp\\dist\\vendor.js:22907:18) at EventEmitter.module.exports.Subject.next (C:\\Users\\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) at SafeSubscriber.schedulerFn [as _next] (C:\\Users\\samir\\Desktop\\angular-core new\\ClientApp\\dist\\vendor.js:3762:56) at 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\\dist\\vendor.js:23001:22) at Subscriber.module.exports.Subscriber._next (C:\\Users\\samir\\Desktop\\angular-core new\\ClientApp\\dist\\vendor.js:22943:26) at Subscriber.module.exports.Subscriber.next (C:\\Users\\samir\\Desktop\\angular-core new\\ClientApp\\dist\\vendor.js:22907:18) at EventEmitter.module.exports.Subject.next (C:\\Users\\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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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