英文:
ReferenceError in Angular driving me crazy
问题
I am working on a program and I am implementing a function with click. Now it has been a while since I did Angular, but this referenceError is driving me crazy. I have a function.
dosomeshit(stringelement: string): void{
console.log("reached function: " + stringelement);
}
which is activated by this button.
<div class="flexcontainer">
<div class="card" style="width: 18rem; margin-left: 2%;">
<div class="card-header">
<h2>Overzicht:</h2>
</div>
<ul class="list-group list-group-flush">
<li class="list-group-item" *ngFor="let stringelement of elements">
<div class="flexinsideli">
<div style="width: 90%;">
<p> {{stringelement}} </p>
</div>
<div>
<button type="button" onclick="dosomeshit(stringelement)">
<fa-icon class="fa-1x" [icon]="faPlus"></fa-icon>
</button>
</div>
</div>
</li>
</ul>
<div class="login-alert-msg" *ngIf="errorMessageList">{{errorMessageList}}</div>
</div>
</div>
now I keep getting a referenceError: 14 Uncaught ReferenceError: dosomeshit is not defined when I use click nothing happens at all. Why is my function not reached when I click the button? Why would dosomeshit not be defined? I did define it in my ts file.
英文:
I am working on a program and I am implementing a function with click. Now it has been a while since I did Angular, but this referenceError is driving me crazy. I have a function.
dosomeshit(stringelement: string): void{
console.log("reached function: " + stringelement);
}
which is activated by this button.
<div class="flexcontainer">
<div class="card" style="width: 18rem; margin-left: 2%;">
<div class="card-header">
<h2>Overzicht:</h2>
</div>
<ul class="list-group list-group-flush">
<li class="list-group-item" *ngFor="let stringelement of elements">
<div class="flexinsideli">
<div style="width: 90%;">
<p> {{stringelement}} </p>
</div>
<div>
<button type="button" onclick="dosomeshit(stringelement)">
<fa-icon class="fa-1x" [icon]="faPlus"></fa-icon>
</button>
</div>
</div>
</li>
</ul>
<div class="login-alert-msg" *ngIf="errorMessageList">{{errorMessageList}}</div>
</div>
now I keep getting a referenceError: 14 Uncaught ReferenceError: dosomeshit is not defined
at HTMLButtonElement.onclick ( ..
when I use click nothing happens at all. Why is my function not reached when I click the button? Why would dosomeshit not be defined? I did define it in my ts file.
答案1
得分: 0
使用(click)
而不是onclick
或click
。它应该能够正常工作。这是在Angular中进行事件绑定的正确语法。
英文:
Instead of onclick
or click
use (click)
. It should work. This is the right syntax in Angular for event binding.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论