简体   繁体   English

Angular中的变量和点之间有多余的空间,如何清理?

[英]Surplus space between the variable and dot in Angular, how can I clean up it?

I have a condition block with ng-container in my Angular html template.我的 Angular html 模板中有一个带有ng-container的条件块。 The rendered html contains unexplained space for me, how can I work it around?渲染的 html 包含无法解释的空间,我该如何解决?

The template part:模板部分:

                         <span>
                            <ng-container [ngSwitch]="languageService.currentLang">
                                <ng-container
                                    *ngSwitchCase="'en'">{{accessSubscriptionPlan.subjects[0]?.nameEn}}
                                </ng-container>
                                <ng-container
                                    *ngSwitchCase="'ru'">{{accessSubscriptionPlan.subjects[0]?.nameRu}}
                                </ng-container>
                                <ng-container
                                    *ngSwitchCase="'tt'">{{accessSubscriptionPlan.subjects[0]?.nameTt}}
                                </ng-container>
                            </ng-container>
                            <ng-container *ngIf="accessSubscriptionPlan.subjects[1]">
                                <!--<a [routerLink]="['/subject', accessSubscriptionPlan.subject?.id, 'view']">{{accessSubscriptionPlan.subject?.name}}</a>-->
                                <ng-container [ngSwitch]="languageService.currentLang">&
                                    <ng-container
                                        *ngSwitchCase="'en'">{{accessSubscriptionPlan.subjects[1]?.nameEn}}
                                    </ng-container>
                                    <ng-container
                                        *ngSwitchCase="'ru'">{{accessSubscriptionPlan.subjects[1]?.nameRu}}
                                    </ng-container>
                                    <ng-container
                                        *ngSwitchCase="'tt'">{{accessSubscriptionPlan.subjects[1]?.nameTt}}
                                    </ng-container>
                                </ng-container>
                            </ng-container>
                            .</span>
                            <span
                                jhiTranslate="businesslogic.shop.subscription.platform">Platform Subscription</span>

And the final html, that was generated is:最后生成的 html 是:

<div> 
   <span> <!----> <!----><!---->Mental arithmetics  <!----> <!---->  <!----><!----> <!---->&amp; <!----><!---->Speed reading  <!----> <!---->   .</span> 
   <span jhitranslate="businesslogic.shop.subscription.platform">Platform Subscription.</span> 
</div>

Why do I have spaces between...reading and dot?为什么我在...阅读和点之间有空格?

UPD. UPD。

I tried not to use span , but I still us ng-container and still getting the spaces:我尝试不使用span ,但我仍然使用ng-container并且仍然获得空格:

<div *ngIf="accessSubscriptionPlan.subjects[0]">
                                <!--<a [routerLink]="['/subject', accessSubscriptionPlan.subject?.id, 'view']">{{accessSubscriptionPlan.subject?.name}}</a>-->
                                <ng-container [ngSwitch]="languageService.currentLang">
                                    <ng-container
                                        *ngSwitchCase="'en'">{{accessSubscriptionPlan.subjects[0]?.nameEn}}
                                    </ng-container>
                                    <ng-container
                                        *ngSwitchCase="'ru'">{{accessSubscriptionPlan.subjects[0]?.nameRu}}
                                    </ng-container>
                                    <ng-container
                                        *ngSwitchCase="'tt'">{{accessSubscriptionPlan.subjects[0]?.nameTt}}
                                    </ng-container>
                                </ng-container>
                                <ng-container *ngIf="accessSubscriptionPlan.subjects[1]">
                                    <!--<a [routerLink]="['/subject', accessSubscriptionPlan.subject?.id, 'view']">{{accessSubscriptionPlan.subject?.name}}</a>-->
                                    <ng-container [ngSwitch]="languageService.currentLang">&
                                        <ng-container
                                            *ngSwitchCase="'en'">{{accessSubscriptionPlan.subjects[1]?.nameEn}}
                                        </ng-container>
                                        <ng-container
                                            *ngSwitchCase="'ru'">{{accessSubscriptionPlan.subjects[1]?.nameRu}}
                                        </ng-container>
                                        <ng-container
                                            *ngSwitchCase="'tt'">{{accessSubscriptionPlan.subjects[1]?.nameTt}}
                                        </ng-container>
                                    </ng-container>
                                </ng-container>
                                .
                                <span
                                    jhiTranslate="businesslogic.shop.subscription.platform">Platform Subscription</span>
                            </div>

and the output is: output 是:

<div> <!----> <!----><!---->Mental arithmetics  <!----> <!---->  <!----> . <span jhitranslate="businesslogic.shop.subscription.platform">Platform Subscription.</span> </div>

The problem is with that the span is an inline element.问题在于span是一个内联元素。 That's why the parser keeps every white-space in it.这就是解析器保留每个空格的原因。

So every new line and tab and space will be trimed into 1 space.因此,每个新行、制表符和空格都会被修剪成 1 个空格。

Try using other element like div or so.尝试使用其他元素,如 div 左右。

Here is the current version of the code that eliminates the whitespaces. 是消除空格的代码的当前版本。

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

相关问题 我如何在角度2的2个分量之间共享变量值 - How can i share a variable value between 2 components in angular 2 Angular2如何清理AppModule - Angular2 How to clean up the AppModule 如何在有角项目的html组件之间传递字符串变量作为参数? - how can I pass a string variable as argument between the html components of an angular project? 如何重用角度打字稿中的变量? - How can I reuse a variable in angular typescript? 如何使用缓存在 Angular 9 中的组件实例之间维护变量的值? - How can I maintain a variable's value between component instances in Angular 9 with caching? 如何在 Angular 中创建全局变量? - How can i make global variable in Angular? 如何在多个 Angular 2 项目之间共享 Angular 2 组件? - How can I share an Angular 2 component between multiple Angular 2 projects? 如何在 TabStripItem - nativescript(Angular + Android)中显示红点或数字作为徽章 - How can i show a red dot or a number as badge in TabStripItem - nativescript (Angular + Android ) 如何清理 Angular 2+ 项目,以便可以将其压缩并通过电子邮件发送 - How do I clean an angular 2+ project so it can be zipped and emailed 我怎样才能启动并运行这个有角度的项目? - how can I get this angular project up and running?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM