1
  <tbody>
    <tr *ngFor="let item of  _studentList let i=index">
    <td  align='center'>{{ i }}--{{item.rollno}}</td>
    <td  align='center'>{{item.sname}}</td>
    <td  align='center'>{{item.status!='NOT'?item.status:''}}</td>
    <td  align='center'>
        <input type='checkbox'   style='height:15px; width:15px;' [checked]="item.status=='P'"  (change)="onChangePA(item)"  ></td>
  <td  align='center'>
   <a><img src='../images/d.jpg' height='30' width='30' /> </a>
 </td>
 </tr>
 </tbody>

enter image description here

When ever i change the checkbox I will do API request, until i get the response I want to either disable that row or showing loading on row

how to do it?

I want only one loading not all. how to do it?

enter image description here

2
  • are you making an api call after click on checkbox? Commented Jan 18, 2017 at 4:44
  • yes I am updating data in database so it take some time so i want to show waiting msg on row so not allow click again on same row before completing first process Commented Jan 18, 2017 at 4:46

3 Answers 3

3

You can make table row as component and disable input as below import {Component, Input} from '@angular/core'

@Component({
  selector: 'table-body',
  template: `

    <td  align='center'>{{ i }}--{{item.rollno}}</td>
    <td  align='center'>{{item.sname}}</td>
    <td  align='center'>{{item.status!='NOT'?item.status:''}}</td>
    <td  align='center'>
        <input type='checkbox' style='height:15px; width:15px;' [checked]="item.status=='P'"  (change)="onChangePA(item)" [disabled]="disableinput"></td>
  <td  align='center'>
   <a><img src='../images/d.jpg' height='30' width='30' /> </a>
 </td>
  `,
})
export class tBody {
  @Input() item:any;
   @Input() i:any;
  disableinput: false;
  onChangePA(val) {
    this.disablebody = true;
//do your stuff 
  }
}

Your main template will be as below

  <table>
  <thead>
  <tr>
  <th>Roll</th>
  <th></th>
  <th>Status</th>
  <th>Action</th>
    <th></th>
  </tr>
  </thead>
  <tbody>
    <tr *ngFor="let item of  _studentList let i=index">
      <table-body [item]="item" [i]="i"></table-body>
 </tr>
 </tbody>
 </table>

Plunk Link

Sign up to request clarification or add additional context in comments.

4 Comments

Updated plunkr please check now.
still not working for mutiple row and your plunkr not showing any output
check properly i am able to see plunkr output.
ReferenceError: System is not defined console showing this error
2

Demo

Basically you will need to have a variable in the component which informs the template whether the api call is initiated or completed.

Initially "showLoading" will be false. Set it to "true" when the api call is being made. After you get the response set it to "false".

And in your template, you will have a "class binding" like this -

<div>
      <div [class.loading]=showLoading>
        I'm a div that wants to be styled
      </div>
      <button (click)="toggle()">Toggle</button>
</div>

class App {
  public showLoading = false;

  toggle() {
    this.showLoading = !this.showLoading;
  } 
}

6 Comments

sorry did not get you?
I want to pass different loading for row then above not work for me
what different loading? be specific
suppose when I click on first rollno checkbox then for only that row showing loading msg same for other it easy to clearify which row updating
please put your code in some online editor and I will help you out.
|
1

Maybe try this

In Html:

<input type="checkbox" (change)="onClick()" [disabled]="isDisable" />

In .ts file:

export class YourComponent {

  isDisable = false;

  onClick() {
    this.isDisable = true;
    //Your code here
    this.isDisable = false;
  }

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.