Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

231
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda