how to set text inside md-progress-spinner in Angular-4

為{幸葍}努か 提交于 2019-12-22 12:23:17

问题


In Angular-4 I am setting progress spinner like that

 <md-progress-spinner [color]="color" [mode]="mode" [value]="value" aria-label="Rating">Rating</md-progress-spinner>

and the values in ts:

  color = 'warn';
  mode = 'determinate';
  value = 50;
  showText='Rating';

But I want to set some text inside the progress bar, I try to use angular-2 method but its not working in Angular-4 can anybody please tell me how its done in Angular-4

Angular-2 approach is to set [showText]='showText'


回答1:


This feature in not available in Material. You need to create it manually. You can place the <mat-progress-spinner> inside a <div> and add another <div> inside that to display the text and adjust position manually:

<div>
    <mat-progress-spinner [color]="color" 
                        [mode]="mode" 
                        [value]="value" 
                        aria-label="Rating">
    </mat-progress-spinner>
    <div style="position:relative; top: -60px; left: 30px;">Rating</div>
</div>

Link to stackblitz demo.




回答2:


Here is a better solution

<div class="card border-0" [style.width.px]="185">
   <mat-progress-spinner [color]="'warn'" [mode]="'determinate'" [strokeWidth]="18" [diameter]="185" [value]="56" class="card-img">
   </mat-progress-spinner>

   <div class="card-img-overlay d-flex justify-content-center align-items-center p-0">
     <div class="card border-0 bg-transparent" [style.width.px]="135">
        <mat-progress-spinner [color]="'primary'" [mode]="'determinate'" [strokeWidth]="7" [diameter]="135" [value]="100" class="card-img">
        </mat-progress-spinner>

        <div class="card-img-overlay d-flex justify-content-center align-items-center p-0">
           <h1 class="letter-spacing text-muted text-center font-weight-normal">
              56%
              <h6 class="text-uppercase">
                 <small class="letter-spacing-2 font-weight-500">increase</small>
              </h6>
           </h1>
        </div>
     </div>
   </div>
</div>

You would need bootstrap 4 css for this as prerequisite.



来源:https://stackoverflow.com/questions/46365836/how-to-set-text-inside-md-progress-spinner-in-angular-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!