angular - Kendo Angular 2 主题

标签 angular kendo-ui-angular2

我正在尝试弄清楚如何自定义主题,如下所述:

http://www.telerik.com/kendo-angular-ui/components/styling/

我不明白的是在“自定义主题”部分下。它描述了能够直接在您自己的应用程序中更改 scss 变量,但这对我不起作用。我到底需要什么引用资料才能做到这一点?

$accent: #ff69b4;

@import "~@progress/kendo-theme-default/scss/all";

我可以将其放入我的组件样式文件中...但我仍然缺少一些东西(它什么也不做)。

他们在此处引用的“模块的正确路径”是什么?

@Component({
  selector: 'my-app',
  styleUrls: [
    // load the default theme (use correct path to modules)
    'styles.scss'

最佳答案

由于style encapsulation ,如果您将其放入组件中,它将仅应用于组件自己的 html。

您希望您的主题应用于整个 html,因此您可以将其放在根组件(通常是应用程序组件)上,并将 ViewEncapsulation 设置为 none,或者将其放在 <head> 中声明的全局 scss 文件中。 .

这是第一个选项的一些代码(我认为是最干净的):

app.component.ts:

@Component({
    selector: 'app',
    template: require('./app.component.html'),
    encapsulation: ViewEncapsulation.None,
    styles: [require('./app.component.scss')]
})

app.component.scss:

/* Redefine here all the kendo theme variables you want */
$accent: red;

@import "~@progress/kendo-theme-default/scss/all";

现在,这意味着您必须能够在项目中使用 scss。 例如,使用 webpack,您可以这样做:

module: {
    loaders: [
        { test: /\.scss$/, loader: 'to-string!css!sass' },
        ...

您将需要使用 css-loader 和 sass-loader npm 包。

您可以在 _variables.scss 文件中找到所有可以自定义的变量: https://github.com/telerik/kendo-theme-default/blob/master/scss/_variables.scss

关于angular - Kendo Angular 2 主题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41856955/

相关文章:

javascript - 从 Angular 4 中的输入类型日期添加月份至今

javascript - 在 Angular2 中使用 Protractor

angular - 将服务相关组件移至共享模块

angular - 如何在 Angular 中处理 Kendo 网格复选框事件

kendo-ui - 使用 OData 枚举作为字段过滤网格

kendo-grid - 剑道与 Angular2 : How to display custom message when there are no records available in Kendo Grid

javascript - URL 重定向到不受信任的站点

javascript - Ionic 2 - 使用参数在页面之间导航(空白应用程序)

angular - 使用 Kendo UI for Angular 以编程方式隐藏 GridComponent 中的列

kendo-ui-angular2 - Angular2 的 Kendo UI - 网格行选择