简体   繁体   English

如何在 Angular 6 中创建应用配置服务来配置 ngbTooltips?

[英]How do I create an app config service to configure ngbTooltips in Angular 6?

All,全部,

I am trying to keep my app component clean and was hoping to create an app config service to globally set my ngbTooltips.我试图保持我的应用程序组件干净,并希望创建一个应用程序配置服务来全局设置我的 ngbTooltips。

In my app component (app.component.ts) I have the following在我的应用程序组件(app.component.ts)中,我有以下内容

@Component({
  selector: 'root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
  providers: [NgbTooltipConfig]
})
export class AppComponent implements OnInit {
  constructor(private readonly appConfigService: AppConfigService
  ) {}   

 ngOnInit() {}
}

And in my app config service (app.config.service.ts), I have the following在我的应用程序配置服务(app.config.service.ts)中,我有以下内容

@Injectable({
  providedIn: 'root'
})
export class AppConfigService {
  constructor(private readonly ngbTooltipConfig: NgbTooltipConfig) {
    ngbTooltipConfig.placement = 'bottom';
    ngbTooltipConfig.container = 'body';
  }
}

When I hover over a ngbTooltip, it always has it's placement as 'top'?当我在 ngbTooltip 上 hover 时,它总是将其放置为“顶部”?

What am I missing?我错过了什么? I am injecting AppConfigService into AppComponent so shouldn't tooltip placement be 'bottom' everywhere?我将 AppConfigService 注入到 AppComponent 中,所以工具提示位置不应该在任何地方都是“底部”吗?

Thx谢谢

Sorry, I figured out my issue.抱歉,我发现了我的问题。

I shouldn't have had我不应该有

providers: [NgbTooltipConfig]

in app component.在应用程序组件中。

Thx谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM