如何在角引号中设置p-listbox的宽度?

问题描述 投票:0回答:1

我正在尝试将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

css angular primeng
1个回答
0
投票

您不能直接从其他组件更改组件样式,而需要使用:: ng-deep

dashboard.component.css

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

另一个选项primeng通过提供自定义类提供了一种更改任何组件样式的方法way

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

在全局样式文件中

style.css

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

选中此👉demo 🚀🚀

© www.soinside.com 2019 - 2024. All rights reserved.