我正在学习Angular通过以下一本书,我来到了一个任务,我必须实现一个评级组件使用bootstrap.当我编译我的代码,评级组件不出现,我不能找到错误...
- 额定值.组件. ts**
@Component({
selector: "rating",
template:`<i
class="glyphicon"
[class.glyphicon-star-empty]="rating < 1"
[class.glyphicon-star]="rating >= 1"
(click)="onClick(1)"
>
</i>
`
})
export class RatingComponent{
rating = 0;
onClick(ratingValue:any){
this.rating = ratingValue;
}
}
- 应用程序.组件. ts**
@Component({
selector: 'app-root',
template: `
<rating></rating>`,
})
export class AppComponent {
title = 'Angular Project';
}
- 索引. html**
<html lang="en">
<head>
<meta charset="utf-8" />
<title>MyApp</title>
<base href="/" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="favicon.ico" />
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css"
integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx"
crossorigin="anonymous"
/>
</head>
<body>
<app-root></app-root>
</body>
</html>
- 应用程序模块. ts**
import { BrowserModule } from '@angular/platform-browser';
import { ProductsComponent } from './Components/product.component';
import { AppComponent } from './app.component';
import { AdvertisementComponent } from './Components/advertisement.component';
import { MaterialComponent } from './Components/material.component';
import { RatingComponent } from './Components/rating.component';
@NgModule({
declarations: [
AppComponent,ProductsComponent,AdvertisementComponent,MaterialComponent,RatingComponent
],
imports: [
BrowserModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
1条答案
按热度按时间pnwntuvh1#
您正在尝试在Bootstrap5中使用字形图标,它在Bootstrap4中已停用。
如果您真的想使用glyphicon,并且如果使用的是旧版本的Bootstrap,那么这不是问题,您可以使用Bootstrap3更改index.html文件
您的代码只显示一颗星星,您可以显示5颗星,将模板更改为如下形式: