This is my component's code, non of the versions do anything. I just get blank console in browser.
export class AssetsComponent {
s = 'Hello2';
constructor() {
this.s = 'ds';
console.log(this.s); <--- nothing
console.log('test'); <--- nothing
console.log(s); <--- breaks the compiler
}
}
The console. log() is a function in JavaScript which is used to print any kind of variables defined before in it or to just print any message that needs to be displayed to the user.
log Function in Angular. console. log is a JavaScript function that logs messages to the developer's console or the browser console to the web page. This method helps Angular developers by informing them about the errors, warnings, and what is happening during the execution of their code.
If anyone else encounters this problem here's what my error was: in chrome developer tools, under the console there is a setting to hide all output. For whatever reason, it was turned on. I set it back to "Default" and it works now.
It's possible the component isn't being loaded. You didn't include your code showing the whole component file or your app.module file where it should be included. It's also possible it isn't even compiling, because you are trying to access a variable that doesn't exist:
console.log(s); <--- breaks the compiler
There is no variable 's' in the constructor you can access. It needs to be this.s or you need to define a variable s in within the constructor function:
let s = 'something';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With