在角2/2离子一种简单的方法来改变物体的颜色使用主题/ variables.scss文件。
// Named Color Variables
// --------------------------------------------------
// Named colors makes it easy to reuse colors on various components.
// It's highly recommended to change the default colors
// to match your app's branding. Ionic uses a Sass map of
// colors so you can add, rename and remove colors as needed.
// The "primary" color is the only required color in the map.
$colors: (
primary: #488aff,
secondary: #32db64,
danger: #f53d3d,
light: #f4f4f4,
dark: #222,
my-special-color: #ffcc55,
);
我们动态地改变颜色的ionic2页面,您可以做到这一点通过在HTML部分
<button [color]="myBtnColor">MyButton</button>
而在你打字稿部分的颜色结合可变
import { ..., ChangeDetectorRef, ... } from '@angular/core';
...
export class MyComponent {
myBtnColor = "secondary"
constructor(private changeDetectorRef:ChangeDetectorRef) {}
...
function changeColorDynamicaly() {
myBtnColor = "my-special-color";
this.changeDetectorRef.detectChanges();
}
...
}
在我的情况下,ChangeDetectorRef用于查看视图中反映的实际更改。该视图被无效更新。
可能你缺少颜色代码和'!important'之间的空格,所以使用'this.color =“#ffc000!important”;'然后再次检查 – ranakrunal9
http:// stackoverflow。com/questions/32495014/angular-ng-if-ng-style-not-changing-the-table-font-color - >或许这可以为你工作。 – Gene