小编Flo*_*geb的帖子

如何在Visual Studio代码中手动设置语法突出显示的语言

在混乱开始之前,这个问题是关于Code,新的轻量级Visual Studio编辑器.你可以从这里得到它:https://code.visualstudio.com/

我有一个带有CSS的文本文件(.txt),并希望获得语法高亮显示.您可以使用ctrl + shift + p打开命令调色板.但是你不能在Sublime中设置语法.

有没有其他方法可以从我的文本文件中获取CSS着色?

syntax-highlighting editor visual-studio-code

301
推荐指数
6
解决办法
10万
查看次数

打字稿中的枚举和对象有什么区别

我试图通过枚举访问地图的值,并为其中的所有字符串创建一个翻译就绪的应用程序.两个问题都重叠,我必须决定使用枚举还是只使用JSON格式的对象.

那么枚举和对象之间的区别和用途到底是什么?

例如:

  • 我可以使用枚举来访问数组以及插入标签和其他东西

const enum FieldNames {
  FirstField: "Field One",
  SecondField: "Field Two"
};
    
someFieldArray[FieldNames.FirstField].label = FieldNames.FirstField;
someFieldArray[FieldNames.SecondField].label = FieldNames.SecondField;
Run Code Online (Sandbox Code Playgroud)

  • 或者我可以通过对象实现相同的行为

const FieldNames = {
  FirstField: "Field One",
  SecondField: "Field Two"
};

someFieldArray[FieldNames.FirstField].label = FieldNames.FirstField;
someFieldArray[FieldNames.SecondField].label = FieldNames.SecondField;
Run Code Online (Sandbox Code Playgroud)

我真的没有从简单对象中选择枚举的好处.在我看来,一个对象有更多的好处,没有任何缺点.

javascript enums object typescript

22
推荐指数
4
解决办法
6228
查看次数

Angular Material 自定义组件主题

我正在尝试在我的自定义 Angular Material 主题中将自定义调色板中的颜色用于其他一些组件。

例如,带有 mat-toolbar 的 div 和带有边距的图标,应填充主要背景色。

关于主题的 Angular Material 指南说:

不应将主题文件导入其他 SCSS 文件。这将导致重复的样式写入您的 CSS 输出。

但是在组件主题的指南中,它说明了以下内容:

您可以使用@angular/material/theming 中的主题函数和材料调色板变量。您可以使用 mat-color 函数从调色板中提取特定颜色。例如:

// Import theming functions
@import '~@angular/material/theming';
// Import your custom theme
@import 'src/unicorn-app-theme.scss';

// Use mat-color to extract individual colors from a palette as necessary.
// The hue can be one of the standard values (500, A400, etc.), one of the three preconfigured
// hues (default, lighter, darker), or any of the aforementioned prefixed with "-contrast".
// …
Run Code Online (Sandbox Code Playgroud)

sass angular-material angular

8
推荐指数
2
解决办法
5548
查看次数

如何从库导入组件(在带有 Angular 的 nrwl/nx 中)

我想将PageNotFoundComponent我的ui-components库中的内容导入到我的应用程序的路由器中。

当我将 导入UiComponentsModule到 myAppModule并使用模板中的组件时,一切正常,但以 es6 表示法导入组件失败。

/libs/ui-components/src/lib/ui-components.module.ts

import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { ContactCardComponent } from './contact-card/contact-card.component';
import { NotFoundComponent } from './not-found/not-found.component';
import { WhiteLabelFooterComponent } from './white-label-footer/white-label-footer.component';
import { WhiteLabelHeaderComponent } from './white-label-header/white-label-header.component';

@NgModule({
  declarations: [
    ContactCardComponent,
    WhiteLabelFooterComponent,
    WhiteLabelHeaderComponent,
    NotFoundComponent
  ],
  exports: [
    ContactCardComponent,
    WhiteLabelFooterComponent,
    WhiteLabelHeaderComponent,
    NotFoundComponent
  ],
  imports: [CommonModule],
})
export class UiComponentsModule {}
Run Code Online (Sandbox Code Playgroud)

/apps/myApp/src/app/app-routing.module.ts

import { NgModule } from '@angular/core'; …
Run Code Online (Sandbox Code Playgroud)

typescript angular nrwl nrwl-nx

8
推荐指数
1
解决办法
2万
查看次数

在Angular 4中的子模块中使用AppModule中的组件

我已经在LoadingComponent我的应用程序的根目录中创建了一个小的component()并且(显然)在我的应用程序中声明了它AppModule.我的应用程序加载时会使用此组件,并应显示一些奇特的加载动画.

现在我想在保存一些东西时在子模块中使用它.但是当我想在另一个模块中使用这个组件时,我总是会遇到错误.

我在AppModule中导出了LoadingComponent:

import { ButtonsModule } from './buttons/buttons.module';
import { FormsModule } from '@angular/forms';
import { StatusLightsDisplayComponent } from './status-lights-display/status-lights-display.component';
import { StatusLightsContainerComponent } from './status-lights-container/status-lights-container.component';
import { HttpModule } from '@angular/http';
import { ReportsService } from './services/reports.service';
import { BrowserModule } from '@angular/platform-browser';
import { forwardRef, NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { GeneralInformationComponent } from './general-information/general-information.component';
import { TextfieldsComponent } from './textfields/textfields.component';
import { LoadingComponent } from './loading/loading.component'; …
Run Code Online (Sandbox Code Playgroud)

angular-module angular

7
推荐指数
2
解决办法
9737
查看次数

Angular 应用程序不再构建。未找到 build-long.md

对 @Angular-devkit/build-Angular 包进行小幅更新后,构建脚本不再工作。当我开始构建时ng build app --base-href /app/ --output-path ./dist/app/de/ --deployUrl /en/app/ --configuration=dev出现未处理的异常:

An unhandled exception occurred: File C:\Users\<User>\Projects\<project>\angular\node_modules\@angular\cli\commands\build-long.md was not found while constructing the subcommand build.

之后我升级到最新版本 9 并重新安装完整的软件包,结果相同。我也更新了@angular/cli,但@angular/compiler-cli没有任何改变。我删除了该node_modules文件夹并重新安装了所有内容。问题依然存在...

然后我降级@angular-devkit/build-angular到版本0.802.2.(低于升级前我们使用的版本)并出现完全相同的问题。

我查看了压缩包,没有任何build-long.md文件。为什么会出现这个问题?有人可以帮忙吗?

angular-cli angular

6
推荐指数
1
解决办法
760
查看次数

如何在 Angular 和 Jasmine 中进行取消订阅单元测试?

例如,我的组件中有私有类成员

private querySubscription: Subscription;

在我的ngOnDestroy()订阅中取消订阅:

ngOnDestroy(): void { this.querySubscription.unsubscribe(); this.userSettingsSubscription.unsubscribe(); }

如何在茉莉花单元测试中测试我是否确实正确取消订阅?我可以以编程方式调用,ngOnDestory()因为它是公共的,但我无法测试我的私有类成员。

unit-testing observable jasmine angular

5
推荐指数
1
解决办法
7798
查看次数

Material Design Table不接受dataSource对象

我收到以下错误:

compiler.js:486未捕获错误:模板解析错误:无法绑定到'dataSource',因为它不是'table'的已知属性.

我正在将表插入自定义材料模态组件,该组件应显示历史条目列表.

HistoryComponent:

import { Component, OnInit, ViewChild } from "@angular/core";
import { MatTableDataSource, MatSort } from "@angular/material";

@Component({
  selector: "app-history",
  templateUrl: "./history.component.html",
  styleUrls: ["./history.component.scss"],
})
export class HistoryComponent implements OnInit {
  displayedColumns = ["position", "name", "weight", "symbol"];
  dataSource = ELEMENT_DATA;

  constructor() { }

  ngOnInit() {
  }

}

export interface Element {
  name: string;
  position: number;
  weight: number;
  symbol: string;
}
const ELEMENT_DATA: Element[] = [
  {position: 1, name: "Hydrogen", weight: 1.0079, symbol: "H"},
  {position: 2, name: "Helium", weight: …
Run Code Online (Sandbox Code Playgroud)

javascript typescript material-design angular-material angular

2
推荐指数
1
解决办法
4534
查看次数