[英]Angular2 notify Component about DOM elements created outside angular
我在Angular2項目中使用Swiper輪播。 用Webpack構建它。
眾所周知,Angular2會附加組件中的所有元素,例如_ngcontent-pmm-6
等隨機屬性。
Swiper動態創建分頁元素(點,項目符號,按照你想要的方式調用它們)。 據我所知,這發生在Angular之外。 所以這些元素沒有那些時髦的屬性,Angular不了解它們。
現在問題:當Angular處理組件的css(通過styleUrls
添加)時,它將此屬性添加到css選擇器
.swiper-pagination-bullet { ... }
成為
.swiper-pagination-bullet[_ngcontent-pmm-6] { ... }
但是分頁是在Angular之外呈現的,而新元素沒有這個屬性,所以樣式不起作用 。
如何通知Angular2有關在Angular之外創建的元素?
https://angular.io/docs/ts/latest/guide/component-styles.html#!#inspect-generated-css
我找到了解決問題風格的解決方法。 但這不是回答我的問題。 如果有人知道,聽到會很優雅!
import { Component, ViewEncapsulation } from '@angular/core';
@Component({
selector: 'cmp',
template: `<div class="cmp">Component</div>`,
styles: ['.cmp { border: green 2px solid; }'],
encapsulation: ViewEncapsulation.None // Use to disable CSS Encapsulation for this component
})
export class Component {
constructor() { }
}
答案在這里找到: https : //coryrylan.com/blog/css-encapsulation-with-angular-2-components
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.