【发布时间】:2018-09-15 03:30:09
【问题描述】:
我遇到了一个有点奇怪的问题:::ng-deep 与常规 CSS 配合得很好,但是当我尝试切换到 SASS 时,我发现所有使用 ::ng-deep 声明的样式(我需要使用 @ 987654325@ 更改某些 Angular Material 样式),不适用。但所有其他样式都可以正常工作。
需要说,我使用的不是纯 Angular:
"ionic-angular": "3.9.2",
"@angular/*": "5.0.3",
"@ionic-native/*": "4.5.3",
...
这是我在 .angular-cli.json 中的defaults:
{
...
"defaults": {
"styleExt": "scss", // also tried with "sass"
"component": {}
}
}
这是我的 sass.config.js(不确定您需要哪些行,所以我会发布完整文件):
module.exports = {
outputFilename: process.env.IONIC_OUTPUT_CSS_FILE_NAME,
sourceMap: false,
outputStyle: 'expanded',
autoprefixer: {
browsers: [
'last 2 versions',
'iOS >= 8',
'Android >= 4.4',
'Explorer >= 11',
'ExplorerMobile >= 11'
],
cascade: false
},
includePaths: [
'node_modules/ionic-angular/themes',
'node_modules/ionicons/dist/scss',
'node_modules/ionic-angular/fonts',
'node_modules/font-awesome/scss'
],
includeFiles: [
/\.(s(c|a)ss)$/i
],
excludeFiles: [
/* /\.(wp).(scss)$/i */
],
variableSassFiles: [
'{{SRC}}/theme/variables.scss'
],
directoryMaps: {
'{{TMP}}': '{{SRC}}'
},
excludeModules: [
'@angular',
'commonjs-proxy',
'core-js',
'ionic-native',
'rxjs',
'zone.js'
]
};
我在迁移过程中是否遗漏了什么?如果您需要更多信息 - 只要问,我会更新问题。
component.ts:
@Component({
selector: 'app-pincode-enter',
templateUrl: './pincode-enter.component.html',
styleUrls: ['/pincode-enter.component.scss'], // this path is correct, styles without "::ng-deep" works fine
encapsulation: ViewEncapsulation.None // tried all 3 properties
})
pincode-enter.component.scss 在同一个文件夹中。
pincode-enter.component.scss:
/* Tried both with "::ng-deep" and without */
:host .mat-button-wrapper {
line-height: 72px;
background-color: red !important;
color: yellow !important;
}
:host ::ng-deep .mat-button-wrapper {
line-height: 72px;
background-color: red !important;
color: yellow !important;
}
以上样式不适用:
我也尝试将此样式移动到全局样式表,但再次失败。
【问题讨论】:
-
编译时是否显示错误或静默失败?
-
没有错误,
:host ::ng-deep ...的所有样式(我现在在 scss 上)都不适用(以及其他变体)。 -
发布您的
component.ts、style.scss,只有相关部分才可以。我曾经将css更改为sass但忘记在component.ts文件中更新:) -
@sabithpocker,我已经更新了问题
标签: angular ionic-framework sass ionic3 angular-material