Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

229
Views
angular 2 user can do one click on the button then it becomes disabled

Hello i am developing angular 2 app ; I have entity article(id , title , text , vote) , account(id) , likes(articleid and userid) I have a button called like . I want if the user click on the button like the button becomes disabled and vote increase . I did a bit of code that works but the button is not disabled . this is my function in the typescript side :

Like(Article,likes:Likes) {

    Article.vote += 1;
    this.articleService.modifier(Article)
        .subscribe((res: Article) => this.onSaveSuccess(res), (res: 
    Response) => this.onSaveError(res.json()));

   this.likes= new Likes;
   this.likes.articleid=Article.id;
    this.principal.identity().then((account) => {
        this.currentAccount = account;
    });
    this.likes.userid=this.currentAccount.firstName;
    this.likesService.create(this.likes)
        .subscribe((res: Likes) => this.onSaveSuccess2(res), (res:  
    Response) => this.onSaveError(res.json()));
}

This is the HTML side :

   <span *ngFor="let article of articles ;trackBy: trackId">
   <div style="margin-left: 30px; padding-top: 20px;">
   <div class="row">
   <h3 >{{article.titre}}</h3><br/>
   <p >{{article.text}}</p><br/>
   <div  > <strong >Publié par</strong><p >{{article.utilisateur}}</p></div>




   <p style="float:right;padding-right: 50px;margin-left: 5px;">    
     {{article.vote}}</p>

<span *ngFor="let likes of likess ;trackBy: trackId">

  <span *ngIf="likes.articleid === article?.id &&
                   likes.userid === account.id">

         <button type= "submit"
                 (click)=" Like(article,likes)"
                 disabled

                 class="btn btn-danger btn-sm">
                        <span class="fa fa-thumbs-up"></span>

                    </button>
    </span>
    <span *ngIf="likes.articleid != article?.id || !likes.articleid  ">

         <button type= "submit"
                 (click)=" Like(article,likes)"


                 class="btn btn-danger btn-sm">
                        <span class="fa fa-thumbs-up"></span>

                    </button>
    </span>

</span>
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

When clicked on button set any property to true like Article.disabled = true and add the disabled directive on button like [disabled]="article.disabled".

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!