Hola, estoy desarrollando la aplicación angular 2; Tengo artículo de entidad (id, título, texto, voto), cuenta (id), Me gusta (id de artículo e ID de usuario) Tengo un botón llamado Me gusta. Quiero que si el usuario hace clic en el botón, me gusta que el botón se deshabilite y aumente el voto. Hice un poco de código que funciona pero el botón no está deshabilitado. esta es mi función en el lado mecanografiado:
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())); }Este es el lado HTML:
<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>Cuando se hace clic en el botón, establezca cualquier propiedad en verdadero como Article.disabled = true y agregue la directiva deshabilitada en el botón como [disabled]="article.disabled" .