我正在尝试将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;
}
答案 0 :(得分:1)
您不能直接从其他组件更改组件样式,而需要使用:: ng-deep
dashboard.component.css
:host ::ng-deep p-listbox .ui-listbox-list{
width: 20rem;
}
另一个选项primeng通过提供自定义类provide提供了一种更改任何组件样式的方法
<p-listbox styleClass="listbox-20rem" [options]="cities1" [(ngModel)] ="selectedCity1" optionLabel="name">
</p-listbox>
在全局样式文件中
style.css
.listbox-20rem .ui-listbox-list {
width: 20rem;
}
检查此?demo ??