无法从 angular 中的 ng-bootstrap 库获取属性值
not able to fetch the attribute value from ng-bootstrap lib in angular
目前我正在使用 ng-bootstrap datepicker 并尝试从 ngb-datepicker-month 组件中获取属性值“aria-label”,但我无法访问 DOM直接,但是我尝试使用 jQuery 但它没有获取值。有没有办法在 ng-datepicker 库中获取 attr 值?
打字稿:
ngOnInit()
{
$(document).ready(() => {
console.log('arial-label: ',$('.ngb-dp-week .hidden').get('aria-label'));
function formtDate(date) {
var d = new Date(date),
day = <any>d.getDate();
if(<any>day.length < 2) {
day = day;
}
return day;
}
console.log(formtDate("Moday, October 8, 2020"));
});
}
HTML:
您可以使用 ViewChild
。试试这个:
app.component.html
<div role="gridcell" class="ngb-dp-day hidden" aria-label="Monda, August 31, 2020" #ariaLabel></div>
app.component.ts
import { Component, ViewChild, ElementRef } from "@angular/core";
@Component({
selector: "my-app",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.css"]
})
export class AppComponent {
// Getting the reference
@ViewChild(ariaLabel, { static: false }) div: ElementRef;
ngAfterViewInit() {
console.log( this.div.nativeElement);
}
}
目前我正在使用 ng-bootstrap datepicker 并尝试从 ngb-datepicker-month 组件中获取属性值“aria-label”,但我无法访问 DOM直接,但是我尝试使用 jQuery 但它没有获取值。有没有办法在 ng-datepicker 库中获取 attr 值?
打字稿:
ngOnInit()
{
$(document).ready(() => {
console.log('arial-label: ',$('.ngb-dp-week .hidden').get('aria-label'));
function formtDate(date) {
var d = new Date(date),
day = <any>d.getDate();
if(<any>day.length < 2) {
day = day;
}
return day;
}
console.log(formtDate("Moday, October 8, 2020"));
});
}
HTML:
您可以使用 ViewChild
。试试这个:
app.component.html
<div role="gridcell" class="ngb-dp-day hidden" aria-label="Monda, August 31, 2020" #ariaLabel></div>
app.component.ts
import { Component, ViewChild, ElementRef } from "@angular/core";
@Component({
selector: "my-app",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.css"]
})
export class AppComponent {
// Getting the reference
@ViewChild(ariaLabel, { static: false }) div: ElementRef;
ngAfterViewInit() {
console.log( this.div.nativeElement);
}
}