我与ionic5一起使用了Angular 9,我需要从我的打字稿代码中获取当前使用的模式(字符串md
或ios
与平台可能不同的模式)。因此,我的问题是,是否可以直接从打字稿代码中实现此操作而无需从htmlmode
属性标签中读取它。
我试图查阅有关Platform样式的官方文档,但这仅考虑CSS内的用法。
查找这些内容的最简单方法是查看Ionic的源代码,尤其是providers
文件夹。在那里,我找到了以下文件:https : //github.com/ionic-team/ionic-framework/blob/master/angular/src/providers/config.ts
该文件公开Config
提供程序,该公开程序将公开应用程序的整个配置,包括mode
。
请看一下这个工作中的Stackblitz演示
import { Component, OnInit } from "@angular/core";
import { Config } from "@ionic/angular";
@Component({
selector: "app-home",
templateUrl: "./home.page.html",
styleUrls: ["./home.page.scss"]
})
export class HomePage implements OnInit {
public mode: string;
constructor(private config: Config) {}
ngOnInit() {
// Replace the mode in the app.module.ts
// file to test this
this.mode = this.config.get("mode");
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句