标签: angular-cli

角度服务库

在最新版本的 Angular cli 中,我们可以使用ng g library lib-name命令来创建库。如 Angular文档中所述:

ng serve <project>
Run Code Online (Sandbox Code Playgroud)

和:

<project>   The name of the project to build. Can be an app or a library.
Run Code Online (Sandbox Code Playgroud)

所以,我们可以为library提供服务。但是当我服务时,我收到以下错误:

Project 'ngx-tab-component' does not support the 'serve' target.
Error: Project 'ngx-tab-component' does not support the 'serve' target.
at ServeCommand.initialize (C:\Users\vahidnajafi\angular\ngx-tab-app\node_modules\@angular\cli\models\architect-command.js:53:19)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
at Function.Module.runMain (module.js:695:11)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:612:3
Run Code Online (Sandbox Code Playgroud)

angular-cli angular angular-library

4
推荐指数
3
解决办法
7576
查看次数

Angular CLI 'ng' 未被识别为有效命令

NodeJS 版本:v10.0.0

npm 版本:5.6.0

在我执行 'npm install -g @angular/cli' 后,它已成功安装

但是当我尝试运行“ng”命令时:“ng”不被识别为内部或外部命令

angular-cli

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

angular 应用中指定的入口点在哪里

我是 angular 的新手,并使用 angular-cli 安装了示例 angular 应用程序。这有 package.json 文件,该文件通常必须具有该应用程序的入口点。但是我没有发现在这个预定义的 pakage.json 文件中被定义。angular 应用程序的入口点在哪里指定,为什么不在 package.json 文件中按预期指定。

package.json angular-cli angular

4
推荐指数
1
解决办法
9744
查看次数

部署到 Linux 应用服务时,Angular CLI 应用未运行

我正在尝试使用 Azure Dev Ops 将 Angular CLI 应用程序部署到 Linux 操作系统上的 Azure 应用服务 - 但没有成功。我得到图像 1。服务器或应用程序日志中没有错误。

图 1

这是我到目前为止所做的:

  1. 使用 DevOps Build 构建了 Angular CLI 应用程序,并将生成的“dist”文件夹放置到“drop”文件夹中。请参阅下面(图 2)构成我的构建的任务。这工作正常并创建了预期的文件。

图 2

  1. 在 DevOps 中创建了一个版本,在 Linux 中的 Azure 应用服务中部署 wwwroot 文件夹中的所有 dist 文件。下面显示了运行 ng build --prod 后的 wwwroot 文件夹(左)和我的本地 dist 文件夹(右)。

图 3

我怀疑我需要在进行部署时输入一些命令时间来启动 angular。我试过运行“ng serve --host 0.0.0.0”,但这没有用。

linux azure azure-web-app-service azure-devops angular-cli

4
推荐指数
1
解决办法
2746
查看次数

IntelliJ IDEA + Angular ng-serve 在每次更改时重新编译

我正在使用 IntelliJ IDEA 开发一个 Angular 应用程序。我在终端窗口中运行 ng server 。每当我更改任何代码时,angular cli 都会自动重新编译,并导致浏览器不断重新加载。我希望 angular cli 仅在单击“构建项目”图标或按 Ctrl+S 时重新编译。我花了几个小时查看 IntelliJ 和 angular cli,但找不到任何关于如何实现它的信息。如果你知道如何请帮助

intellij-idea serve angular-cli angular

4
推荐指数
1
解决办法
3593
查看次数

将 NgRx 和 Angular 升级到版本 7 后无法编译

我正在将使用 NgRx 的 Angular 应用程序从版本 6.1.3 升级到 7.2.15。运行后ng-update我的版本升级如下:

角度 - 6.1.3 -> 7.2.15

NgRx - 6.1.0 -> 7.4.0

RxJS - 6.2.2 -> 6.5.2

rxjs-compat(第三方组件需要) - 6.2.2 -> 6.5.2

在升级编译失败并返回以下错误的变体后,尝试构建或提供应用程序时,对于所有使用选择器的地方:

  Types of parameters 'source$' and 'source' are incompatible.
    Type 'Observable<MyFeatureState>' is not assignable to type
src/app/my-feature/detail/detail.component.ts(84,45): error TS2345: Argument of type '(source$: Observable<State>) => Observable<DetailMetadata[]>' is not assignable to parameter of type 'OperatorFunction<MyFeatureState, DetailMetadata[]>'.
Run Code Online (Sandbox Code Playgroud)

我没有使用任何非常复杂的选择器。大多数只是直接从功能商店获取值,并且应用程序在升级之前就可以运行。作为其中一个组件的(简化)示例,错误指向:

  Types of parameters 'source$' and 'source' are incompatible.
    Type 'Observable<MyFeatureState>' is not assignable to …
Run Code Online (Sandbox Code Playgroud)

ngrx angular-cli angular angular7

4
推荐指数
1
解决办法
691
查看次数

运行 Angular e2e 测试时如何禁用或绕过 MSAL 身份验证?

我想为我的 Angular 应用程序设置一些端到端测试,这需要使用 MSAL 库来对一些下游服务进行身份验证。当我尝试在本地运行 e2e 测试时,MSAL 库强制我使用用户名/密码进行身份验证。

这是一个问题,因为我们的 CI/CD e2e 测试不应该有任何人为干预;因此,我正在寻找一种方法来绕过 MSAL 身份验证或设置服务帐户进行登录。不幸的是,围绕 Angular 的 MSAL 的文档并不多(尤其是在 e2e 测试方面),但这似乎是其他人可能遇到的常见问题。

我试图从我们的 app.module.ts 文件中禁用 MsalModule 但是当我尝试运行应用程序时仍然提示我登录。我还看到一些文章试图以编程方式登录,但这对我们不起作用,因为从技术上讲,MSAL 不是我们能够接触的 Angular 组件。

app.module.ts:

@NgModule({
  ...
  imports: [
    ...
    MsalModule.forRoot({
      clientID: '<client_id>',
      authority: <microsoft_authority_url>,
      validateAuthority: true,
      redirectUri: "http://localhost:4200/",
      cacheLocation : "localStorage",
      postLogoutRedirectUri: "http://localhost:4200/",
      navigateToLoginRequestUrl: true,
      popUp: true,
      consentScopes: [ "user.read"],
      unprotectedResources: ["https://www.microsoft.com/en-us/"],
      protectedResourceMap: protectedResourceMap,
      logger: loggerCallback,
      correlationId: '1234',
      level: LogLevel.Info,
      piiLoggingEnabled: true
    })
  ],
  entryComponents: [SaveDialogComponent,
                    GenericDialog, MassChangeDialogComponent],
  providers: [TitleCasePipe,
    {provide: HTTP_INTERCEPTORS, useClass: MsalInterceptor, multi: …
Run Code Online (Sandbox Code Playgroud)

e2e-testing angular-cli azure-ad-msal angular angular-e2e

4
推荐指数
2
解决办法
3762
查看次数

ng build --base-href="/.../" --deploy-url="/.../" css 背景图片不起作用

"@angular/core": "~8.0.0",

带有 scss 样式选项的脚手架 angular 8 项目

我在组件 scss 文件中有如下所述的代码

背景: url("/assets/images/vector-icon.png") 不重复 25%;

在最终构建时使用命令

ng build --prod --base-href="/website/" --deploy-url="/website/"
Run Code Online (Sandbox Code Playgroud)

将 build 放在子文件夹 root/webside

除了背景图像路径外,一切正常

我已经尝试过 ip/website/assets/images/vector-icon.png 那时我能够获得图像。

如果我不想更改每个 css 文件的路径怎么办。

任何帮助,将不胜感激。提前致谢

angular-cli angular scss-mixins angular8

4
推荐指数
2
解决办法
9121
查看次数

给出角度构建时非法状态问题中的错误

我正在开发一个角度应用程序。当我使用ng serve. 但是,当我运行时ng build --prod,它给出了以下错误。

ERROR in Illegal State: referring to a type without a variable {"filePath":"/Users/admin/Documents/projects/simply-science-web-ui/simply-science/node_modules/@angular/forms/forms.d.ts","name":"NgControlStatusGroup","members":[]}
Run Code Online (Sandbox Code Playgroud)

我不明白这是什么问题。请帮我解决这个问题。如果需要任何进一步的信息,请告诉我。

更新:

依赖:

"dependencies": {
    "@angular/animations": "~8.1.2",
    "@angular/common": "~8.1.2",
    "@angular/compiler": "~8.1.2",
    "@angular/core": "~8.1.2",
    "@angular/forms": "~8.1.2",
    "@angular/platform-browser": "~8.1.2",
    "@angular/platform-browser-dynamic": "~8.1.2",
    "@angular/router": "~8.1.2",
    "rxjs": "~6.4.0",
    "tslib": "^1.9.0",
    "zone.js": "~0.9.1"
}
Run Code Online (Sandbox Code Playgroud)

其他:

Angular CLI: 8.1.3
Node: 10.16.0
OS: darwin x64
Angular: 8.1.3
Run Code Online (Sandbox Code Playgroud)

谢谢...

typescript angular-cli angular

4
推荐指数
1
解决办法
5071
查看次数

ng build:无法加载工作区配置文件

当我运行 ng build 命令时,我收到以下错误,

发生未处理的异常:无法加载工作区配置文件:C:...\angular\angular.json 无效的 JSON 字符:“?” 在 0:0。有关更多详细信息,请参阅“C:\Users...\AppData\Local\Temp\ng-I8pYWt\angular-errors.log”。

我试过 npm cache clean --force 然后 npm install 或 yarn

角度errors.log

[error] Error: Workspace config file cannot be loaded: C:\...\angular\angular.json
Invalid JSON character: "?" at 0:0.
at Object.getWorkspace (C:\...\angular\node_modules\@angular\cli\utilities\config.js:59:15)
at BuildCommand.validateScope (C:\...\angular\node_modules\@angular\cli\models\command.js:97:60)
at BuildCommand.validateAndRun (C:\...\angular\node_modules\@angular\cli\models\command.js:122:24)
at Object.runCommand (C:\...\angular\node_modules\@angular\cli\models\command-runner.js:186:38)
at process.runNextTicks [as _tickCallback] (internal/process/task_queues.js:52:5)
at Function.Module.runMain (internal/modules/cjs/loader.js:880:11)
at internal/main/run_main_module.js:21:11
Run Code Online (Sandbox Code Playgroud)

版本

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.800.6
@angular-devkit/build-angular     0.800.6
@angular-devkit/build-optimizer   0.800.6
@angular-devkit/build-webpack     0.800.6
@angular-devkit/core              8.3.9
@angular-devkit/schematics        8.3.9
@angular/cdk                      8.2.3
@angular/cli                      8.3.9
@ngtools/webpack                  8.0.6 …
Run Code Online (Sandbox Code Playgroud)

angular-cli angular ng-build

4
推荐指数
1
解决办法
5111
查看次数