ReferenceError在Angular中让我疯狂

huangapple go评论67阅读模式
英文:

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(&quot;reached function: &quot; + stringelement);
  }

which is activated by this button.


&lt;div class=&quot;flexcontainer&quot;&gt;
    &lt;div class=&quot;card&quot; style=&quot;width: 18rem; margin-left: 2%;&quot;&gt;
        &lt;div class=&quot;card-header&quot;&gt;
            &lt;h2&gt;Overzicht:&lt;/h2&gt;
          &lt;/div&gt;

        &lt;ul class=&quot;list-group list-group-flush&quot;&gt;
            &lt;li class=&quot;list-group-item&quot; *ngFor=&quot;let stringelement of elements&quot;&gt;
              &lt;div class=&quot;flexinsideli&quot;&gt;
                &lt;div style=&quot;width: 90%;&quot;&gt;
                  &lt;p&gt; {{stringelement}} &lt;/p&gt;  
                &lt;/div&gt;
              &lt;div&gt;
                &lt;button type=&quot;button&quot; onclick=&quot;dosomeshit(stringelement)&quot;&gt;
                    &lt;fa-icon class=&quot;fa-1x&quot; [icon]=&quot;faPlus&quot;&gt;&lt;/fa-icon&gt;
                &lt;/button&gt; 
              &lt;/div&gt;
            &lt;/div&gt;          
            &lt;/li&gt;
        &lt;/ul&gt;

        &lt;div class=&quot;login-alert-msg&quot; *ngIf=&quot;errorMessageList&quot;&gt;{{errorMessageList}}&lt;/div&gt;
    &lt;/div&gt;

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)而不是onclickclick。它应该能够正常工作。这是在Angular中进行事件绑定的正确语法。

英文:

Instead of onclick or click use (click). It should work. This is the right syntax in Angular for event binding.

huangapple
  • 本文由 发表于 2023年5月26日 16:15:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76338930.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定