1

I am working on Angular 4 framework. I wanted to add a material progress bar to my app's homepage. I followed the official guide for Angular Material environment set up.

After that I added the code for progress bar in .html file and compiled. It is not been updated on the web page. How can I resolve this?

The HTML code is:

<mat-card>
  <mat-card-content>
    <h2 class="example-h2">Progress bar configuration</h2>

    <section class="example-section">
      <label class="example-margin">Color:</label>
      <mat-radio-group [(ngModel)]="color">
        <mat-radio-button class="example-margin" value="primary">
          Primary
        </mat-radio-button>
        <mat-radio-button class="example-margin" value="accent">
          Accent
        </mat-radio-button>
        <mat-radio-button class="example-margin" value="warn">
          Warn
        </mat-radio-button>
      </mat-radio-group>
    </section>

    <section class="example-section">
      <label class="example-margin">Mode:</label>
      <mat-radio-group [(ngModel)]="mode">
        <mat-radio-button class="example-margin" value="determinate">
          Determinate
        </mat-radio-button>
        <mat-radio-button class="example-margin" value="indeterminate">
          Indeterminate
        </mat-radio-button>
        <mat-radio-button class="example-margin" value="buffer">
          Buffer
        </mat-radio-button>
        <mat-radio-button class="example-margin" value="query">
          Query
        </mat-radio-button>
      </mat-radio-group>
    </section>

    <section class="example-section" *ngIf="mode == 'determinate' || mode == 'buffer'">
      <label class="example-margin">Progress:</label>
      <mat-slider class="example-margin" [(ngModel)]="value"></mat-slider>
    </section>
    <section class="example-section" *ngIf="mode == 'buffer'">
      <label class="example-margin">Buffer:</label>
      <mat-slider class="example-margin" [(ngModel)]="bufferValue"></mat-slider>
    </section>
  </mat-card-content>
</mat-card>

<mat-card>
  <mat-card-content>
    <h2 class="example-h2">Result</h2>

    <section class="example-section">
      <mat-progress-bar
          class="example-margin"
          [color]="color"
          [mode]="mode"
          [value]="value"
          [bufferValue]="bufferValue">
      </mat-progress-bar>
    </section>
  </mat-card-content>
</mat-card>

and the corresponding component.ts file code is

@NgModule({

  imports: [MatButtonModule, MatCheckboxModule],

})
@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.scss']
})

export class HomeComponent  {
  color = 'primary';
  mode = 'determinate';
  value = 50;
  bufferValue = 75;
}
9
  • Do you have any output in console ? Can you give us your material version ? There was some changes with prefixes for their components. Commented Nov 7, 2017 at 9:52
  • no output in dashboard.nothing is visible. Commented Nov 7, 2017 at 10:08
  • @angular/material": "^2.0.0-beta.12 Commented Nov 7, 2017 at 10:09
  • some of the other material components like radio button,checkbox etc are visible as output.but progress bar is not. Commented Nov 7, 2017 at 10:11
  • Check in browser inspector. (for example in chrome in DevTools there is tab elements) if mat-progress-bar is generated in html file, also check my answer, maybe there is problem with imports. Commented Nov 7, 2017 at 10:13

8 Answers 8

4

As far as I can there is missing imports. You have to add this to your @NgModule

import {MatProgressBarModule} from '@angular/material';

and in @NgModule

imports: [MatButtonModule, MatCheckboxModule, MatProgressBarModule],
Sign up to request clarification or add additional context in comments.

2 Comments

it is added but no result
Thx. Why this magic is missed from the official getting started tutorial?!
2

You have to add this or any prebuilt theme to your css file

@import '~@angular/material/prebuilt-themes/deeppurple-amber.css';

Comments

2

In case you've imported the following module, try to remove it

import {NoopAnimationsModule} from '@angular/platform-browser/animations';

1 Comment

Yep that was it noopanimations
1

I had a strange problem. My container(div) was displayed as flex and that was somehow rendering the progress bar having 0 height even though I had the height set to 4px. I have no idea as to how and why it happened. So I wrapped the progress bar in another container (div with default display) and the progress bar started showing up.

Comments

0

Maybe I'm too late for this but since the last angular material update the import changed to:

import { MatProgressBarModule } from '@angular/material/progress-bar';

Hope this helps.

Comments

0

Possibly you need the BrowserAnimationsModule to be imported in your app. Check out the link https://material.angular.io/guide/getting-started on how to get it installed. As per your example, also try setting the section with class example-section to have 100% width. Hope that helps.

Comments

0

My problem was that the progress bar div had 0 width and height. Wrap the progress tag around a div and give it a class of progress-div. Then add this code to your css:

.progress-div{
    height: auto;
    width: auto;
}

Comments

0

I had to target the overflow of the progress bar, it was set to "hidden"

    mat-progress-bar.mat-mdc-progress-bar{
        overflow:visible;
    }

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.