conditionally show and hide button using angular 6

ngif=show hide div
angular 6 show more show less
angular hide component
angular 4 [hidden] example
ng-show angular 6
toggle in angular 6
angular button hidden
show/hide div based on dropdown selection angular 4

Actually i am trying to disable the button when the task is running. Once the task finished loading i want to activate the button. Means paralally the sync icon spins when the task status is in 'In_progress' once the status changes to 'Completed' the spinner should be hidden and the button 'AutoCode Sync' should be activated. So how to achieve that one. For that i have written the below code:

<section *ngFor="let task of tasksRes">
    <nav>
        <span class="text-warning" *ngIf="task?.status == 'In_progress'"><i class="fa fa-spinner fa-spin"></i></span> 
    </nav>

    <div class="pull-right">
        <button mat-raised-button color="primary" (click)="open();" class="btn-w-md">
        AutoCode Sync
        </button>
    </div>
</section>

Can anyone please help me in this to achieve? Thanks.

Use ngIf with your condition (status === Completed) to show/hide the button

<div class="pull-right">
    <button mat-raised-button color="primary" (click)="open();" class="btn-w-md" *ngIf="task?.status == 'Completed'"">
    AutoCode Sync
    </button>
</div>

How to Show Hide or Toggle Elements in Angular 4, I wish to show and hide the elements with the click of a button. Read: How to Implement AutoComplete feature in Angular 6 with Dynamic Data using Web API. We all must be knowing how it was in Angular js 1. Before starting on Angular js 2, if you are interested to know how it was in Angular js 1, you can refer below posts. 1. Angular js 1 Show and hide 2. Angular js 1 loader. In angular js 1 it was ng-show and ng-hide, and also you can use ng-if as well. Let us check how it is in Angular 2.

Disable the button conditionally using [disabled]

<button mat-raised-button color="primary" (click)="open();" class="btn-w-md" [disabled]="task?.status == 'In_progress'">
        AutoCode Sync
</button>

Angular toggle or hide show element on button click, Often it is required to show an element on click of a button or a link and hiding it again on click. In simpler words, toggle element display on each click. Practical  AngularJS has four different directives (ng-show / ng-hide, ng-if, ng-include, ng-switch), which are used to conditionally display or hide the HTML DOM elements. Conditional display using ng-show/ng-hide. The ng-show / ng-hide directives require a boolean value to evaluate the visual state. This boolean value may come from a variable or a function.

You can use [hidden] property on both the spinner and button but I'm not sure why you are using *ngFor="let task of tasksRes" do you get more than one buttons and spinner

<section *ngFor="let task of tasksRes">
    <nav [hidden]="task?.status == 'Completed'" >
        <span class="text-warning" *ngIf="task?.status == 'In_progress'"><i class="fa fa-spinner fa-spin"></i></span> 
    </nav>

    <div class="pull-right" [hidden]="task?.status == 'In_progress'">
        <button mat-raised-button color="primary" (click)="open();" class="btn-w-md">
        AutoCode Sync
        </button>
    </div>
</section>

this will act a toggle that shows and hides button based on the condition

You can either add a separate property as true and false to and read it based on your condition - hope this works - Happy coding !!

NgIf, A structural directive that conditionally includes a template based on the @​Component({ selector: 'ng-if-simple', template: ` <button (click)="show = !show">{{​show ? To display a template when expression evaluates to false, use an else text is hidden</ng-template> ` }) export class NgIfElse { show: boolean = true; }​  Must read: Perform CRUD operations using an HTML table in Angular 6 using Web API. The second property (optional) is buttonName of type any. It has a default value as Show. I also wish to change the name of the button for every click. That is, it should show the name as Show when the elements are hidden and change to Hide when the elements are

You can add any document attribute by [attr.{{attribute}}] in angular.

<div class="pull-right">
    <button mat-raised-button [attr.disabled]="task?.status == your_situation" color="primary" (click)="open();" class="btn-w-md">
    AutoCode Sync
    </button>
</div>

Difference Between NgIf And Hidden Or Display:none In Angular , hidden attribute in html5 and display none CSS will show or hide the HTML element. We will go through the examples to understand them further. A structural directive that conditionally includes a template based on the value of an expression coerced to Boolean. When the expression evaluates to true, Angular renders the template provided in a then clause, and when false or null, Angular renders the template provided in an optional else clause.

AngularJS: API: ngHide, ng-hide CSS class is predefined in AngularJS and sets the display style to none (​using an !important flag). For CSP mode please add angular-csp.css  Join a community of over 2.6m developers to have your questions answered on Conditionally show or hide Command button in command column of UI for WinForms Buttons, RadioButton, CheckBox, etc.

Make It Easy: Show and hide in angular 2(+)., In angular js 1 it was ng-show and ng-hide, and also you can use ng-if <div> <​button (click)="ShowButton()">Show Result</button> <button  This is the tag which we are going to show/hide based on the ng-show attribute. In the controller, we are attaching the "IsVisible" member variable to the scope object. This attribute will be passed to the ng-show angular attribute (step#2) to control the visibility of the div control.

Angular 9/8 ngIf Tutorial & Example, you'll be learning about how you can use ngIf in your Angular 6 applications. The ngIf directive in Angular allows you to do conditional rendering of template parts i.e you can show or hide an HTML element on your Angular 9 HTML need to use the ngIf directive and show or hide the actions' buttons  The main difference between angular ngIf directive & hidden or display:none is ngIf will add or remove the element from DOM based on condition or expression. hidden attribute in html5 and display none CSS will show or hide the HTML element. We will go through the examples to understand them further. Table of Contents. ngIf in Angular

Comments
  • you can conditionally disable the button [disabled]="task?.status=='In_progress'"
  • While this might answer the authors question, it lacks some explaining words and/or links to documentation. Raw code snippets are not very helpful without some phrases around them. You may also find how to write a good answer very helpful. Please edit your answer - From Review