Angular CLI 项目 Bootstrap 成功或危险 class 未加载
Angular CLI project Bootstrap has-success or has-danger class not loading
我还有一个问题要问社区,这个很简单。正如之前的问题,我正在研究 Asim Hussain 先生 "Angular4 From Theory to Practice" 的书,运行 遇到了 bootstrap 的问题。has-danger 和 .has-success classes not在职的。我用
安装了 bootstrap
npm install bootstrap --save
在 .angular-cli.json
中添加了 bootstrap css 的路径
"styles": [
"../node_modules/bootstrap/dist/css/bootstrap.min.css",
"styles.css"
],
一切似乎都运行良好,网格和表单样式加载良好,控制台中没有错误。当我在练习后实施验证时出现问题,表单字段边框没有按应有的方式变为红色或绿色,这是我的代码
<!-- One of the fields from the form -->
<div class="form-group"
[ngClass]="{
'has-danger': f.form.controls.email?.invalid && (f.form.controls.email?.dirty || f.form.controls.email.touched),
'has-success': f.form.controls.email?.valid && (f.form.controls.email?.dirty || f.form.controls.email.touched)
}">
<label>Email</label>
<input type="email"
class="form-control"
name="email"
[(ngModel)]="model.email"
required
pattern="[^ @]*@[^ @]*">
</div>
不确定为什么 bootstrap class 没有将文本字段变成红色或绿色,有人可以帮我解决这个问题吗?
问题已有 7 个月大,但回答可能对其他人有所帮助。
.has-danger
已不存在。
这个问题已经在这里问过:
我还有一个问题要问社区,这个很简单。正如之前的问题,我正在研究 Asim Hussain 先生 "Angular4 From Theory to Practice" 的书,运行 遇到了 bootstrap 的问题。has-danger 和 .has-success classes not在职的。我用
安装了 bootstrapnpm install bootstrap --save
在 .angular-cli.json
中添加了 bootstrap css 的路径"styles": [
"../node_modules/bootstrap/dist/css/bootstrap.min.css",
"styles.css"
],
一切似乎都运行良好,网格和表单样式加载良好,控制台中没有错误。当我在练习后实施验证时出现问题,表单字段边框没有按应有的方式变为红色或绿色,这是我的代码
<!-- One of the fields from the form -->
<div class="form-group"
[ngClass]="{
'has-danger': f.form.controls.email?.invalid && (f.form.controls.email?.dirty || f.form.controls.email.touched),
'has-success': f.form.controls.email?.valid && (f.form.controls.email?.dirty || f.form.controls.email.touched)
}">
<label>Email</label>
<input type="email"
class="form-control"
name="email"
[(ngModel)]="model.email"
required
pattern="[^ @]*@[^ @]*">
</div>
不确定为什么 bootstrap class 没有将文本字段变成红色或绿色,有人可以帮我解决这个问题吗?
问题已有 7 个月大,但回答可能对其他人有所帮助。
.has-danger
已不存在。
这个问题已经在这里问过: