Angular 单击以更改零部件样式
如果单击按钮,我想向组件添加新样式。 我想换一下 死亡是我的.componenet.scss 新版本是my2.componenet.scss 这是我的组件加载,我会在单击函数时更改样式URLAngular 单击以更改零部件样式,angular,click,components,styles,Angular,Click,Components,Styles,如果单击按钮,我想向组件添加新样式。 我想换一下 死亡是我的.componenet.scss 新版本是my2.componenet.scss 这是我的组件加载,我会在单击函数时更改样式URL @Component({ selector: 'mycomponent', templateUrl: './mycomponent.component.html', styleUrls: ['./mycomponent.component.scss'], }) 这是我的职责 public
@Component({
selector: 'mycomponent',
templateUrl: './mycomponent.component.html',
styleUrls: ['./mycomponent.component.scss'],
})
这是我的职责
public LoadDefaultStyle(){
// loading it styleUrls: ['./my.componenet.scss'], after rendering page
}
public LoadNewStyle(){
// loading it styleUrls: ['./my2.componenet.scss'], after rendering page
}
你能给我一些指导吗?请在不同的两个类中编写样式,并在单击时切换该类
<div class="test_class" (click)="changeColor()"
[ngClass]="status ? 'success' : 'danger'">
Some content
</div>
let status: boolean = false;
changeColor(){
this.status = !this.status;
}
.success{
color: green;
}
.danger{
color: red;
}
一些内容
let状态:boolean=false;
changeColor(){
this.status=!this.status;
}
.成功{
颜色:绿色;
}
.危险{
颜色:红色;
}
也许你可以用这个答案?这似乎与你的问题非常相似。嗨,我认为这不是达到你要求的正确方法。请参阅Angular theming document==>它对我有用mangeshbhuskute