我正在尝试实现一个投票系统,其中活跃投票的背景为蓝色。为此,我使用 2 个布尔值来跟踪分数和所选选项。我尝试使用 NgClass,但我似乎无法弄清楚它在我的情况下是如何工作的,因为我会在现有的 2 个类中添加一个额外的类。
CSS
.voting{
cursor: pointer;
display: inline;
}
.activeVote{
background: #2980b9;
}
Run Code Online (Sandbox Code Playgroud)
超文本标记语言
投票类和 noSelect 应始终处于活动状态,但单击increaseUpvote() 应将 activeVote 类添加到该类,因为 upvoted 布尔值将为 true。同样的事情也应该发生在否决选项上。
<p style="font-size: 28px;">{{post.upvotes}}
<mat-icon class="voting noSelect" (click)="increaseUpvote()">arrow_upward
</mat-icon>
<mat-icon class="voting noSelect" (click)="increaseDownvote()">
arrow_downward
</mat-icon>
</p>
Run Code Online (Sandbox Code Playgroud)
打字稿
public upvoted: boolean = false;
public downvoted: boolean = false;
increaseUpvote(): void {
if (this.downvoted) {
this.post.upvote();
this.downvoted = false;
}
if (!this.upvoted) {
this.post.upvote();
this.upvoted = true;
} else if (this.upvoted) {
this.post.removeUpvote();
this.upvoted = false; …Run Code Online (Sandbox Code Playgroud) 我在 Angular 6 项目中使用 simplebar 库(https://github.com/Grsmto/simplebar),当我在 html 标签中添加简单栏时,它显示了一个水平和垂直滚动条,所以我只想显示垂直滚动条。
我尝试使用以下 CSS 属性隐藏水平滚动条:
overflow-x: hidden
Run Code Online (Sandbox Code Playgroud)
也具有以下属性:
width:100%" and "position:abolute" or "position:relative"
<div data-simplebar style="overflow-x: hidden">
<div *ngFor="let example of examples;">
<div>{{example.title}}</div>
<p>{{example.text}}</p>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我希望只显示水平滚动条,但它似乎不起作用,我不知道是否缺少某些内容或某些 CSS 属性,或者 Angular 是否导致了此问题。
我需要显示 s3 签名 url 作为文件对象返回的 pdf。我正在尝试使用 ng2-pdfjs-viewer 来显示。但这似乎不起作用。
我尝试直接使用 s3 url 到 pdfSrc 但它不起作用。
组件.html:
<ng2-pdfjs-viewer pdfSrc="pdfUrl"></ng2-pdfjs-viewer>
Run Code Online (Sandbox Code Playgroud)
组件.ts
previewProtocol(){
//this.spinner.show();
this.service.getS3Url(deviceType).subscribe((response) => {
$('#BSModal').modal("show");
console.log(response);
this.pdfUrl = response;
},
(err)=> {
});
Run Code Online (Sandbox Code Playgroud)
}
我有一个问题。
我正在尝试通过 *.js 文件将一些数据从一个表“传输”到另一个表。一切都很顺利,除了一件事。这个函数向我展示了:
Error: Timezone "gmt+0200" is not recognized
Run Code Online (Sandbox Code Playgroud)
这是我的功能
async function submitCompletationCG(database, ulogin, idc) {
await connectToSpecificDatabase(database);
const AC_ID = `SELECT * FROM public.cg_actualcompletations WHERE UserLogin = '`+ulogin+`';`;
let AC_IDs = await client.query(AC_ID);
const ACC_ID = `SELECT * FROM public.cg_actualcompletationscondensed WHERE UserLogin = '`+ulogin+`';`;
let ACC_IDs = await client.query(ACC_ID);
const DEPOT = `SELECT * FROM public.cg_actualdepots WHERE UserLogin = '`+ulogin+`';`;
let DEPOTs = await client.query(DEPOT);
let depot_from, depot_to, code_from, code_to;
for(let Depot of DEPOTs.rows) {
depot_from = Depot.depot_from; …Run Code Online (Sandbox Code Playgroud) 我在 Iframe 中使用我的 Angular 应用程序,并且我希望能够在执行构建(ng build)后更改 index.html 中的 javascript 文件的路径。
这是我用来构建我的 Angular 应用程序的命令:
npm run env && ng build --aot --prod --environment=prod
Run Code Online (Sandbox Code Playgroud)
完成后,在我的 dist 文件夹中我有这棵树:
index.html
inline.318b50c57b4eba3d437b.bundle.js
main.d83bd9b8af8c676f706b.bundle.js
and etc
Run Code Online (Sandbox Code Playgroud)
查看index.html我们可以看到以下内容:
<body>
...
<script type="text/javascript" src="inline.318b50c57b4eba3d437b.bundle.js"></script>
<script type="text/javascript" src="polyfills.5a5809ec73e38d8a32d3.bundle.js"></script>
<script type="text/javascript" src="scripts.7b67fa96a25429619fd6.bundle.js"></script>
<script type="text/javascript" src="main.d83bd9b8af8c676f706b.bundle.js"></script>
</body>
Run Code Online (Sandbox Code Playgroud)
我想以某种方式更改构建命令,也许有一个我没有看到的标志或任何其他方法来生成具有不同路径的 javascript 文件的 index.html ,如下所示:
<body>
...
<script type="text/javascript" src="PathBefore/inline.318b50c57b4eba3d437b.bundle.js"></script>
<script type="text/javascript" src="PathBefore/polyfills.5a5809ec73e38d8a32d3.bundle.js"></script>
<script type="text/javascript" src="PathBefore/scripts.7b67fa96a25429619fd6.bundle.js"></script>
<script type="text/javascript" src="PathBefore/main.d83bd9b8af8c676f706b.bundle.js"></script>
</body>
Run Code Online (Sandbox Code Playgroud)
当我的编辑表单加载时,我想用初始值填充表单数组。我的下拉选择选项被禁用,但它没有显示在垫选择中。
let selectedSpecs = this.editData.element.specifications;
this.spec = this.specForm.get('spec') as FormArray;
if (selectedSpecs.length != 0){
let selectedAttributeIds = [];
selectedSpecs.forEach((spec, i) => {
let attribute;
attribute = {'id': spec.itemDetailId, 'itemId':this.editData.element.itemId, 'name': spec.name};
this.spec.push(this.formBuilder.group({
attribute: attribute,
attributeSpec: spec.description
}));
selectedAttributeIds.push(spec.itemDetailId);
});
let attributes = [];
this.selectedCatAttributes.forEach((tempattribute) => {
let selected;
if (selectedAttributeIds.includes(tempattribute.id)) {
selected = true;
}else {
selected = false;
}
attributes.push(new Attribute(tempattribute, !selected));
});
this.attributeList.next(attributes);
}
<div formArrayName="spec" *ngFor="let spec of specForm.get('spec')['controls']; let i= index">
<div [formGroupName]="i">
<mat-card class="addShadow">
<button …Run Code Online (Sandbox Code Playgroud) javascript typescript formgroups angular6 angular-material-6
我有一个 Angular 6 应用程序,我想在每次路线更改时存储页面标题,
import { Router, NavigationEnd, NavigationStart, RoutesRecognized } from '@angular/router';
export class AppComponent implements OnInit {
constructor (
public router: Router
) {
}
ngOnInit() {
this.router.events.subscribe(event => {
if (event instanceof NavigationStart) {
// console.log('Starting Navigation');
}
if (event instanceof NavigationEnd) {
console.log('Ending Navigation ', document.title);
}
});
}
Run Code Online (Sandbox Code Playgroud)
问题是每当我想访问当前页面的标题时,它都会显示以前的标题集,但不显示从组件级别动态设置的新标题
有什么建议如何解决这个问题吗?
在我的角度应用程序中,当我在gifts-routing.module.ts中添加路由时,会出现此错误,当我删除路由时,它可以工作,但我仍然需要路由,那么我该如何解决此错误
ERROR Error: Uncaught (in promise): NullInjectorError: StaticInjectorError(AppModule)[FormBuilder]:
StaticInjectorError(Platform: core)[FormBuilder]:
NullInjectorError: No provider for FormBuilder!
NullInjectorError: StaticInjectorError(AppModule)[FormBuilder]:
StaticInjectorError(Platform: core)[FormBuilder]:
NullInjectorError: No provider for FormBuilder!
Run Code Online (Sandbox Code Playgroud)
礼品模块.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { GiftsRoutingModule } from './gifts-routing.module';
import { GiftListComponent } from './components/gift-list/gift-list.component';
import { GiftFormComponent } from './components/gift-form/gift-form.component';
import { SharedModule } from '../shared/shared.module';
@NgModule({
declarations: [GiftListComponent, GiftFormComponent],
imports: [
CommonModule,
GiftsRoutingModule,
SharedModule
]
})
export class GiftsModule { }
Run Code Online (Sandbox Code Playgroud)
礼物路由.module.ts
import { …Run Code Online (Sandbox Code Playgroud) Angular 工作区允许我将多个项目添加到单一存储库中,这很棒。然而,在与多个团队合作时,我注意到,如果您只有一个 package.json 并且让每个团队使用他们正在编写的应用程序对其进行编辑,那么事情可能会变得非常混乱。
\n\n可以有这样的结构吗?
\n\n|\xe2\x94\x80\xe2\x94\x80 angular.json\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 browserslist\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 e2e\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 karma.conf.js\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 node_modules\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 package.json <--- I should only be responsible for everything in /src\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 package-lock.json\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 projects\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 my-sub-application\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 browserslist\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 karma.conf.js\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 package.json <--- Is this possible? So that "my-sub-application" only pulls its dependencies from this package.json?\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 src\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 app\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 assets\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 environments\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 favicon.ico\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 index.html\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 main.ts\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 polyfills.ts\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 styles.scss\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 test.ts\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 tsconfig.app.json\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 …Run Code Online (Sandbox Code Playgroud) 我们一直遇到一个问题,随着时间的推移,随着代码库大小的增加,我们的构建过程会不时由于内存耗尽而失败。我们的短期解决方案只是向进程添加更多内存,但这在很多层面上感觉都是错误的。
我们已经删除了所有旧的和未使用的代码,并采取了我们可以采取的措施来减少重复代码,这确实有所帮助,但随着项目变得更大,我们将再次遇到这个问题。
我们的一个想法是模块化项目的各个部分(无论如何,这是我们想做的事情),但我们不确定这会改善内存使用。我们也不确定边界应该在哪里(但这可能涉及将我们的服务转移到共享模块)。
这些是好主意还是我们找错了对象?在 webpack 期间减少内存使用的最佳方法是什么?