1

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)

3
  • What is the error? Commented Apr 27, 2017 at 10:18
  • I edited the question and added the error. Commented Apr 27, 2017 at 10:21
  • 1
    Try replacing window.console.log(this.categories); with console.log(this.categories); Commented Apr 27, 2017 at 10:23

1 Answer 1

3
window.console.log(this.categories);

should be

console.log(this.categories);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.