1

I do have an Angular component in a for loop like this:

<div *ngFor="let schedule of schedules">
   <my-app-component [schedule]="schedule"></my-app-component>
</div>

The MyAppComponent looks like this:

@Component({
  selector: 'my-app-component',
  templateUrl: '...',
  styleUrls: ['...'],
  encapsulation: ViewEncapsulation.None
})
export class MyAppComponent implements OnInit {

  public disableButtonTrigger: boolean;

 ngOnInit() {
     this.disableButtonTrigger = false;
 }

 someFunction() {
     ...
     this.disableButtonTrigger = true; // this should set disableButtonTrigger to true only for this component and not for all components in the loop
     ...
  }

In the MyAppComponent is a boolean trigger to disable buttons in this component. My problem now is if I set disableButtonTrigger = true than all buttons in all components in the for- loop are disabled. May aim would be that only the buttons on the specific component should be diasbled and not in all component. How can I achive this?

5
  • How exactly are you setting the disableButtonTrigger = true? Via the parent component? Please add enough code so we can understand better what you are implementing. Commented Oct 20, 2024 at 18:14
  • Cannot reproduce in StackBlitz, there it's working as expected: stackblitz.com/edit/… Please add enough code to reproduce the problem. In the StackBlitz I added two buttons for each component, the second one disables the first one. Commented Oct 20, 2024 at 18:48
  • MAybe its because my "MyAppComponent" is defined in a parent @NgModule and is not standalone. Commented Oct 21, 2024 at 12:28
  • That shouldn't make a difference. Commented Oct 21, 2024 at 12:29
  • You are right. Blame on me - the for loop is in the component - I am so sorry - thanks for your help. Commented Oct 21, 2024 at 12:56

0

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.