ElementRef
オブジェクトをAngular2(Ionic2)で調べており、ElementRef
のpadding
CSS属性を保持できません。angular2:ElementRef CSSパディング属性を取得
次の質問については、[my project] \ src \ app \ app.component.tsと[my project] \ src \ app \ app.module.tsの詳細については説明しません。これらの作業を正しく行うようにしてください。
import { Component, ContentChild, ViewChild, ElementRef } from '@angular/core';
import { NavController, Card, CardContent } from 'ionic-angular';
@Component({
selector:'my-component',
templateUrl: 'my-component.html'
})
export class MyComponentPage {
// @ContentChild("ionCard") ionCard:Card;
// @ContentChild("ionCardContent") ionCardContent:CardContent;
@ViewChild("ionCard") ionCard:ElementRef;
@ViewChild("ionCardContent") ionCardContent:ElementRef;
constructor(public navCtrl:NavController){
}
ionViewWillEnter(){
console.log("ionCard: ", ionCard);
console.log("ionCardContent: ", ionCardContent);
}
}
その後でこのHTMLテンプレート[私のプロジェクト] \ SRC \:
私は[私のプロジェクト] \ SRC \ページは私の-component.ts \私の成分を\の下のコンポーネントでこのコードを持っていますページは私の-component.html \私の成分を\、私が持っている:私は#ionCard
と#ionCardContent
ため(ionWillEnter()
にconsole.log
によって与えられた)のログを見ると
<ion-header>
...
</ion-header>
<ion-content >
<ion-card #ionCard>
<ion-card-content #ionCardContent>
</ion-card-content >
</ion-card>
</ion-content>
は:それらの両方がElementRef.nativeElement.clientWidth
のために持って起こります同じ値。そして、それはおそらく良いですが、Chromeのinspectコンソールで(Stylesタブを介して)#IonCardContent
にpadding
があることがわかります。 <ion-card-content>
の実際の使用可能なスペースの幅は、(ElementRef.nativeElement.clientWidth
- padding
)です。そして、このパディングがElementRef.nativeElement
属性にある場所が見つかりません。
ElementRef.nativeElement.style
を見ると、すべての属性に空の文字列値(0)があります。
私もContentChild
で試してみました(これらの行は私のコードでコメントされており、対応するインポートはファイルの上にあります)。 <ion-card>
と<ion-card-content>
は標準のDOM構文ではないので、試してみる価値があると思います。しかし、その場合は、ログにundefined
が表示されます。
誰でも、Angular2のElementRef.nativeElementのパディング属性に到達する方法を知っていますか?
http://stackoverflow.com/questions/5227909/get-element-padding-value-using-javascript –
@GünterZöchbauerあなたは私を解決策に導きます:[ウィンドウオブジェクト] .getComputedStyle(ionCardContent.nativeElement、null ).paddingLeft);私にパディングを残す(接尾辞はpx)。あなたは答えとしてそれを書いていますか? – nyluje