Why is this not functioning correctly?
<button (click)="console.log('ok');">Display Details</button>
The error message reads:
Cannot read property 'log' of undefined
However, a console.log
statement in the class constructor works as expected:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app3-directives',
templateUrl: './directives.component.html'
})
export class DirectivesComponent implements OnInit {
constructor() { console.log('start') }
ngOnInit() {
}
}
...the 'start' message does print in the console. So why is the button showing it as undefined?