如何更改单击按钮上的按钮名称

问题描述:

我想单击该按钮时显示消息“请求已发送”,但在此处当我单击一个按钮时,所有按钮名称正在更改。可以任何人提示我的帮助。如何更改单击按钮上的按钮名称

import { Component,OnInit} from '@angular/core'; 
import {Http, Response, Headers} from '@angular/http'; 
import {Observable} from 'rxjs/Observable'; 
import {Subject } from 'rxjs/Subject'; 
import {Control,FormBuilder,ControlGroup,Validators} from '@angular/common'; 
import { IDetails } from './pro'; 
import {GetAllList } from './service' 

@Component({ 
    templateUrl: './components/professional/professional.html', 

providers : [GetAllList] 
}) 

export class Professional implements OnInit { 
    id:number; 
    profile_id:number; 
    myText:string="Send Request"; 
    details:IDetails[]; 
    title:string = 'MY SOCIETY'; 
    constructor(private _service:GetAllList) { 

    } 
    ngOnInit(){ 
    this._service.getList() 
      .subscribe(details => this.details = details); 
    } 
    send(index):any{ 
    console.log(index); 
    if(index == index){ 
    this.myText="Request sent"; 
    } 
} 
} 

我的模板,

<h3 class= "head">MY SOCIETY</h3> 
    <!--<hr>--> 
    <div *ngFor="let detail of details" class = "col-sm-12"> 
    <div class="pic col-sm-1"> 
    <img height="60" width="60" [src]='detail.image'>     
    </div> 
    <div class = "col-sm-6"> 
    <div class = "fname col-sm-12"> 
     {{detail.firstname}} 
    </div> 
    <div class ="phone col-sm-12"> 
    {{detail.phone}} 
    </div> 
    <div class ="phone col-sm-12"> 

    </div> 
    </div> 

    <button (click)='send(detail.profile_id)' > {{ myText }}</button> 

    <hr class= "col-xs-12"></div> 

我想要显示的信息“请求发送”按钮被点击,而但在这里,当我在一个按钮,点击所有的按钮名称changing.Can有人建议我帮助。

+0

其他按钮在哪里? –

这是很容易 - 只需通过按钮元素作为模板变量:

<button (click)='send(button, detail.profile_id)' #button>Send Request</button> 

而在你的组件,您可以访问按钮,设置文本,也许禁用它:

send(button, index): void { 
    console.log(index); 

    button.innerHTML = "Request sent"; 
    button.disabled = true; 
} 

Plunker例如用法

+0

当我刷新它时,刷新的名字可以告诉我即使刷新后也能稳定它。 – MMR

+0

你是什么意思?如果刷新页面,整个应用程序将重新初始化,当然,临时值将被重置。 – rinukkusu

+0

当我刷新它的butoon属性也刷新,例如“请求发送”回到“发送请求”。 – MMR