【发布时间】:2018-11-14 05:59:52
【问题描述】:
我有以下代码,我想做两件事:
-
根据
verifyDifficulty(text1)的输出更改条形颜色(返回输入文本的长度 - 模拟密码的难度)一个。如果
verifyDifficulty(text1)<=3那么条形颜色=红色(css 中的简单进度)
湾。如果verifyDifficulty(text1)>3 && verifyDifficulty(text1)<=6那么条形颜色=黄色(css 中的进度-中等)
C。如果verifyDifficulty(text1)>6 && verifyDifficulty(text1)<=9然后栏颜色=浅绿色(css 中的进度困难)
d。 ifverifyDifficulty(text1)==10 then bar color=dark green(css 中的进度非常困难) - 将
aria-valuenow值修改为verifyDifficulty(text1)*10,但当我尝试进行属性绑定时,我收到此错误:无法绑定到“aria-valuenow”,因为它不是'div'
我的.ts:
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
name = 'Angular 6';
text1 = '';
verifyDifficulty(text) {
const result = text.length;
return result;
}
}
我的.html:
<hello name="{{ name }}"></hello>
<div class="pb-1">
<input [(ngModel)]="text1" maxlength="10" placeholder="Text">
</div>
<p>{{verifyDifficulty(text1)}}</p>
<div *ngIf="verifyDifficulty(text1)<=3" class="progress">
<div class="progress-bar progress-easy" role="progressbar" aria-valuenow="60" aria-valuemin="0"
aria-valuemax="100" [style.width]="verifyDifficulty(text1)*10+'%'">
{{verifyDifficulty(text1)*10}}
</div>
</div>
我的.css:
p {
font-family: Lato;
}
.progress-bar.progress-easy{
background-color: #fd0801;
}
.progress-bar.progress-medium{
background-color: #c1b706;
}
.progress-bar.progress-hard{
background-color: #8bdb06;
}
.progress-bar.progress-very-hard{
background-color: #00b006;
}
此代码的现场演示is here
【问题讨论】:
标签: html css angular twitter-bootstrap