我正在阅读有关*ngTemplateOutlet指令的信息。此伪指令的使用是通过模板引用和上下文对象作为参数来动态实例化模板。
我想知道的是,我们在Angular中有很多东西可以实现与* ngTemplateOutlet相同的结果,例如:
我们可以有多个*ngIf可以基于相同组件中的组件变量值呈现不同的模板。我们以类似的方式[ngSwitch]根据不同的值为我们呈现不同的模板。
我们可以通过引用*ngIf相应变量的模板引用变量来使用引用。
对于前一种情况:
<div *ngIf="condition1"> Content 1 </div>
<div *ngIf="condition2"> Content 2 </div>
<div *ngIf="condition3"> Content 3 </div>
Run Code Online (Sandbox Code Playgroud)
对于后者:
<ng-container *ngIf="condition then myTemplate else otherTemplate"></ng-container>
<ng-template #myTemplate> Some content... </ng-template>
<ng-template #otherTemplate> Some content... </ng-template>
Run Code Online (Sandbox Code Playgroud)
如果我们的武器库中有这种方法,那么还能*ngTemplateOutlet增加更多的价值?
有哪些实际用例(如果有的话)不能使用上述方法,而应使用*ngTemplateOutlet指令,还是选择另一种方法来获得相同的结果?
我有一个应用程序,我想添加自动更新功能(它不在市场上).我有所有代码可以检查是否有可用的更新,然后我调用这样的代码:
Intent intent = new Intent(Intent.ACTION_VIEW ,Uri.parse(Configuration.APK_URL));
c.startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
开始下载文件.有没有一种方法可以通过编程方式告诉它"打开"文件以开始安装过程,而无需用户进入下载并单击它?
我正在为我的一个项目实现动态组件.动态组件的概念是它们在需要时进入内存并且在任何模板中都没有引用.
根据官方文档,我们声明这些组件entryComponents以防止它们在树摇动过程中被丢弃,因为它们没有模板参考.
以下是app.module.ts我在那里宣布我的两个动力组件SlideOneComponent,并SlideTwoComponent在在entryComponents阵:
@NgModule({
declarations: [
AppComponent,
ButtonComponent,
AdDirective
],
imports: [
BrowserModule
],
providers: [],
entryComponents: [
SlideOneComponent,
SlideTwoComponent,
],
bootstrap: [AppComponent]
})
export class AppModule { }
Run Code Online (Sandbox Code Playgroud)
上面app.module.ts我得到以下错误:
一旦我将两个动态组件添加到declarations数组,上述错误就会消失.上述官方文档还说我们不需要声明可从组件entryComponents或bootstrap组件访问的组件.我也参观了这个答案,但这似乎并不令人满意,因为它与Ionic有关.
请帮我知道我在哪里失踪.提前致谢!:)
对于学校作业,我们需要使用有角度的材料。我制作了一个自定义主题,名为:weather-theme.scss
该文件中的代码如下:
\n@import '~@angular/material/theming';\n\n@include mat-core();\n\n// Define the palettes for your theme using the Material Design palettes available in palette.scss\n// (imported above). For each palette, you can optionally specify a default, lighter, and darker\n// hue. Available color palettes: https://material.io/design/color/\n$weather-theme-primary: mat-palette($mat-gray, 800, 700, 600);\n$weather-theme-accent: mat-palette($mat-amber, 800, 700);\n\n// The warn palette is optional (defaults to red).\n$weather-theme-warn: mat-palette($mat-red);\n\n// Create the theme object (a Sass map containing all of the palettes).\n$weather-theme-theme: mat-light-theme(\n $weather-theme-primary,\n $weather-theme-accent,\n $weather-theme-warn\n);\n\n// Include theme styles for core and each …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 Ionic 4 中使用<ion-searchbar>. 我的问题是搜索栏的高度,我无法操作它。我知道 Ionic 4 是基于 Web 组件的,它将每个组件都包装在一个 shadow DOM 中,但<ion-searchbar>似乎没有 shadow DOM,如下所示:
与其他组件不同,影子 DOM 在节点中可见,如下所示:
这让我觉得我可以在里面覆盖divwith 类searchbar-input-container,<ion-searchbar>但我不能,甚至 Ionic 官方文档也没有涵盖可以实现这一点的任何属性或变量。请帮忙。