I tried to check if the ng-click binding works, but I seem to run into a more fundamental problem - how to see what happens (or not).
My usual “rough” debugging methods alert() and console.log() seem to be unavailable.
Is it possible to access these functions or something like them from an Angular application?
The plnkr example below shows the "working" event - the action of objects in my component - but my calls to the alert() and log() functions seem ignored.
With that said, is there a way to get some kind of error message when I call a function that doesn't exist? The Chrome console log seems to be showing nothing.
https://embed.plnkr.co/Dvadi8mWlUqTUW865UsI/
I think the “possibly duplicate” question is similar, but in fact it does not speak of an alert () or log () in the header, and various partial answers are usually oriented to Angular 1.x and the controllers - I don’t have the controller.
So part of this question is - do I need a controller? It seems that there may be an easy way to “decorate” my application, but now I only have modules and classes, there is no explicit controller.
Thanks.
I think the best answer below is "ng-click", an expression should be provided, not a function call.
and here is some properly formatted code to show how to call these basic functions in Angular2 (for other newbies):
@Component({ selector: 'app-root', templateUrl: './app.component.html', //template:`<h2>Hello, world</h2>` , styleUrls: ['./app.component.css'] }) export class AppComponent { title = 'Quiz Tool'; quiz = new Quiz(); doAlert(){ console.log('log: test log, yo...'); // black console.debug('debug: test log, yo...'); // blue console.warn('warn: test log, yo...'); // yellow console.info('info: test log, yo...'); // black (with 'i' icon) console.error('error: test log, yo...'); // red alert('test...'); } }
and call the doAlert () method from your HTML:
<button (click)="doAlert();count = count + 1" ng-init="count=0">Increment</button>
Thanks!