gpt4 book ai didi

css - 如何在 Angular primeng中设置p-listbox的宽度?

转载 作者:太空宇宙 更新时间:2023-11-04 05:38:18 27 4
gpt4 key购买 nike

我正在尝试将 p-listbox 组件宽度设置为 10 REM,但是我的更改无法实现。请在这里建议。我正在尝试在 css 类上应用宽度。但是,它不适用。但是,当我在 chrome 开发工具中使用 .ui-listbox-list-wrapper 类在 div 上应用时,它应用得很好。

dashboard.component.ts

import { Component, OnInit } from '@angular/core';  
import { SocialLoginModule, AuthServiceConfig, AuthService } from 'angular-6-social-login';
import { Router } from '@angular/router';
import { SocialUsers } from '../../model/social-users';
class City {
name:string;
code:string;
}


@Component({
selector: 'app-dashboard',
templateUrl: './dashboard.component.html',
styleUrls: ['./dashboard.component.css']
})


export class DashboardComponent implements OnInit {
socialusers = new SocialUsers();

cities1: City[];
selectedCity1:string;



constructor(public OAuth: AuthService, private router: Router) {

this.cities1 = [
{name: 'New York', code: 'NY'},
{name: 'Rome', code: 'RM'},
{name: 'London', code: 'LDN'},
{name: 'Istanbul', code: 'IST'},
{name: 'Paris', code: 'PRS'}
];
}
ngOnInit() {
this.socialusers = JSON.parse(localStorage.getItem('socialusers'));
console.log(this.socialusers);
}
logout() {
this.OAuth.signOut().then(data => {
debugger;
this.router.navigate(['login']);
});
}
}

dashboard.component.html

<p-listbox id="listId" [options] ="cities1" [(ngModel)] ="selectedCity1" optionLabel = "name">

</p-listbox>

selected city={{selectedCity1?.name}}

dashboard.component.css

.ui-listbox-list-wrapper {
width: 20REM;
}

enter image description here

最佳答案

您不能直接从另一个组件更改组件的样式。你需要使用::ng-deep

dashboard.component.css

:host ::ng-deep p-listbox .ui-listbox-list{
width: 20rem;
}

另一种选择:primeng 提供了一种通过提供自定义类来更改任何组件样式的方法 🎉

<p-listbox styleClass="listbox-20rem" [options]="cities1" [(ngModel)] ="selectedCity1" optionLabel="name">
</p-listbox>

在全局样式文件中

样式.css

.listbox-20rem .ui-listbox-list {
width: 20rem;
}

检查这个 👉 demo 🚀🚀

关于css - 如何在 Angular primeng中设置p-listbox的宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59437004/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com