I am currently working one of my first web app projects, and is a bit stuck on transitioning from my "home" state to "overview" state.
app.component.html:
<div ng-click="onTextClicked()" style="cursor: pointer;">
<div >
<h1 >{{time}}</h1>
<h2 >{{activateTitle}}</h2>
</div>
</div>
app.component.scss:
app.component.ts
import { Component } from '@angular/core';
import * as moment from 'moment'
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
activateTitle = 'Click anywhere to open screen';
time;
constructor(){
setInterval(() => {
this.time = moment().format("HH:mm:ss");
}, 1000);
}
onTextClicked()
{
console.log("New state entered");
}
}
When I press anywhere on the screen nothing happens? I would have assumed the console.log would have a log message, but that does seem to be the case?
Why is it not able to call this function?
CodePudding user response:
There is no ng-click
in Angular2 , is click
<div (click)="onTextClicked()" style="cursor: pointer;">...
If you need to do something with the data event, you can pass it in the function as:
<div (click)="onTextClicked($event)" style="cursor: pointer;">...
onTextClicked($event) {
console.log("The event clicked: ", $event);
}