【问题标题】:Click to change component style单击以更改组件样式
【发布时间】:2019-10-28 23:24:59
【问题描述】:

如果我单击一个按钮,我想为我的组件添加一个新样式。 我想切换它。

默认是 my.componenet.scss

新版本是 my2.componenet.scss

它是我的组件加载,当我点击一个函数时我会改变 styleurls

@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
  }

你能给我一些指导吗?

【问题讨论】:

标签: angular click components styles


【解决方案1】:

请在不同的两个类中编写样式并在单击时切换类。

 <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;
}

【讨论】:

    猜你喜欢
    • 2018-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-10
    • 2021-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多