Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/243.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 单击以更改零部件样式_Angular_Click_Components_Styles - Fatal编程技术网

Angular 单击以更改零部件样式

Angular 单击以更改零部件样式,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

如果单击按钮,我想向组件添加新样式。 我想换一下

死亡是我的.componenet.scss

新版本是my2.componenet.scss

这是我的组件加载,我会在单击函数时更改样式URL

@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