0

I am trying to pass a parameter to a function for a given ID. Here is the code of the content of my HTML.

<header class="card-header">
        <p class="card-header-title">
            {{taskName}}
        </p>
        <p class="card-header-icon">
            <span [ngClass]="colorClass">
                <i class="fas fa-circle"></i>
            </span>
            <button class="card-footer-item button is-primary" (click)='deleteTaskById('{{id}}')'>X</button>
        </p>
    </header>

I am a beginner in Angular and I am wondering how can I pass the content of {{id}} in my function in the easiest way.

I have the following error message on my console :

    compiler.js:215 Uncaught Error: Template parse errors:
Unexpected closing tag "button". It may happen when the tag has already been closed by another tag. For more info see https://www.w3.org/TR/html5/syntax.html#closing-elements-that-have-implied-end-tags ("        </span>
            <button class="card-footer-item button is-primary" (click)='deleteTaskById('{{id}}')'>X[ERROR ->]</button>
        </p>
    </header>

Here is my function implementation :

  deleteTaskById(idCard){
    let card = {
      id: idCard,
      deadline: "",
      description: "",
      responsible: {},
      state: "",
      endDate: "",
      priority: ""
    };
    this.taskService.delete(idCard).subscribe(res => {

    });
    console.log("delete task : " + card.id);
  }

Thanks for you help.

3
  • can u add the function implementation here? cuz you are fetching the "id" from the .ts code to the template, then pass "id" to the .ts code again, which is not a good practice. Commented Jun 12, 2018 at 11:17
  • I tried this and I got the following warning compiler.js:215 Uncaught Error: Template parse errors: Parser Error: Got interpolation ({{}}) where expression was expected at column 16 in [deleteTaskById('{{id}}')] in ng:///AppModule/TasksCardComponent.html@9:54 (" <i class="fas fa-circle"></i> </span> <button class="card-footer-item button is-primary" [ERROR ->](click)="deleteTaskById('{{id}}')">X</button> </p> </header> Commented Jun 12, 2018 at 11:17
  • The function works well, I have the ID in my console.log when I put an ID like 1. I will add it if you want. Commented Jun 12, 2018 at 11:19

1 Answer 1

3

It should be just

<button class="card-footer-item button is-primary" (click)="deleteTaskById(id)">X</button>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.