我目前正在處理我的第一個網路應用程式專案之一,并且有點卡在從“家庭”狀態轉換到“概述”狀態。
app.component.html:
<div ng-click="onTextClicked()" style="cursor: pointer;">
<div class="home-page">
<h1 class="time-banner">{{time}}</h1>
<h2 class="home-page-menu-button">{{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");
}
}
當我按螢屏上的任意位置時沒有任何反應?我會假設 console.log 會有一條日志訊息,但似乎確實如此?
為什么不能呼叫這個函式?
uj5u.com熱心網友回復:
Angular2 中沒有ng-click,是click
<div (click)="onTextClicked()" style="cursor: pointer;">...
如果你需要對資料事件做一些事情,你可以在函式中傳遞它:
<div (click)="onTextClicked($event)" style="cursor: pointer;">...
onTextClicked($event) {
console.log("The event clicked: ", $event);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/436742.html
上一篇:為什么貓鼬查詢回傳一個空陣列
