标签: angular-cli

控制台错误:ng.probe 不是函数

昨天我将 Angular CLI 和核心更新到 8.0.0v。之后,我成功初始化了一个新应用程序并运行了它。构建应用程序并在其上提供服务后,localhost:4200我打开控制台并出现错误:

ng.probe 不是函数

我试图研究这个问题,但没有相关信息。

实际结果:

ng serve / npm 启动后,控制台出现问题:

未捕获的类型错误:ng.probe 不是函数。当前控制台状态 当前角度状态

预期结果:

控制台没有错误

javascript debugging angular-cli angular

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

ng --version 显示 Angular 不支持当前版本的 Node (16.8.0)

我刚刚使用nvm和angular/cli(12.2)安装了最新版本的node(16.8)。

但当我跑步时 ng --version

它显示以下内容:

警告:Angular 不支持当前版本的 Node (16.8.0)。

我尝试降级节点并安装节点 14.15,但ng不再工作。

我应该忽略警告并使用节点 16吗?

为什么 ng不能与节点 14.15一起使用?

PS:我使用nvm来管理不同的节点版本

javascript node.js nvm angular-cli angular

24
推荐指数
3
解决办法
9万
查看次数

使用angular-cli时如何添加第三方库?

我想尝试使用angular-cli(https://github.com/angular/angular-cli)创建一个Angular 2应用程序,然后使用ng2-material(https://github.com/justindujardin/ng2-material)用于UI组件.但我只是不明白我必须包含ng2-material库以便使用它.

我创建了一个项目,ng new myproject然后我启动了服务器ng serve并打开了网页,结果很好.下一步,我安装了ng2-material npm install ng2-material --save.然后我添加MATERIAL_PROVIDERS到angular的bootstrap,如下所示https://github.com/AngularShowcase/angular2-seed-ng2-material/blob/master/app/bootstrap.ts.

这导致GET http://localhost:4200/ng2-material/all 404 (Not Found)Web浏览器中出现错误消息,我无法弄清楚如何摆脱它.

angular-cli似乎正在做一些事情来创建一个文件dist夹,其中index.html中使用的一些节点模块最终进入,但我看不到在哪里或如何配置.

angular-material angular-cli angular

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

生成内部模块文件夹

我正在使用基于Angular-CLI骨架的Angular 2应用程序,我习惯用一个目录按模块构建我的src文件夹,并且每个组件都与该模块在同一文件夹中相关.

src
    app
        documents
            document-list.component.ts
            document-list.component.html
            documents.component.ts
            documents.component.html
            document.module.ts
        app.component.ts
        app.module.ts
    main.ts 
Run Code Online (Sandbox Code Playgroud)

现在我正在使用Angular-CLI,我想利用每个功能,但是当我生成一个新组件时,无论如何,当我只想放置它时,它会继续为我的组件创建一个新文件夹在相关文件夹内.

src
    app
        documents
            document-list
                document-list.component.ts
                document-list.component.html
            documents.component.ts
            documents.component.html
            document.module.ts
        app.component.ts
        app.module.ts
    main.ts 
Run Code Online (Sandbox Code Playgroud)

是否有可能保留我以前的结构,这是一种不好的做法吗?该指南建议避免无用的目录深度,所以我有点不安.

angular-cli angular

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

这些angular-cli做了什么:inline.bundle.js,vendor.bundle.js,main.bundle.js?

如果我检查使用angular-cli创建的angular 2项目的index.html文件,我可以看到该页面只包含来自dist文件夹的3个文件:

inline.bundle.js
vendor.bundle.js
main.bundle.js
Run Code Online (Sandbox Code Playgroud)

但现在我试图了解每个文件的作用.我使用angular-cli编写了组件,我已降级,所以我可以在另一个用angular 1编写的应用程序中使用它.如果我只是将这3个文件添加到我的index.html,再加上app.module.ts文件,似乎我已升级我的应用程序,一切正常.我试图解开为什么,因为谷歌角度不是在谈论角度cli以及它如何帮助迁移.

components angular-cli angular

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

ng在子目录中生成组件

我有以下目录结构

在此输入图像描述

我想创建一个新页面,比方说,一个关于页面.我想把它放在src/app/page/about/*

所以我尝试:

ng generate component pages/about
Run Code Online (Sandbox Code Playgroud)

但我得到这个错误:

Error: More than one module matches. Use skip-import option to skip importing the component into the closest module.
More than one module matches. Use skip-import option to skip importing the component into the closest module.
Run Code Online (Sandbox Code Playgroud)

使用页面存储我的单独页面是一个好主意吗?如何使用angular-cli在子目录中生成组件?

angular-cli angular5 ng-generate

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

角度cli 6,ng测试不起作用

我刚刚将角度项目更新为角度6.

ng build和ng服务工作,但是当我使用命令运行我的测试时:

ng test
Run Code Online (Sandbox Code Playgroud)

我得到输出:

Schema validation failed with the following errors:
Data path "" should have required property 'tsConfig'.
Run Code Online (Sandbox Code Playgroud)

tsconfig.json:

{
"compilerOptions": {
"baseUrl": "",
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
  "es2016",
  "dom"
],
"mapRoot": "./",
"module": "es2015",
"moduleResolution": "node",
"outDir": "../dist/out-tsc",
"sourceMap": true,
"target": "es5",
"typeRoots": [
  "../node_modules/@types"
]
}
}
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么 ?

angular-cli angular angular6

23
推荐指数
2
解决办法
5607
查看次数

Angular 6库共享样式表

如何设置index.scss并将变量,mixins等的全局样式表导入角度6库?

Angular CLI生成具有根组件和组件scss的lib,但添加或导入到根组件的样式不可用于子组件.默认情况下,封装样式是有道理的,但我找不到任何关于如何设置它的信息或示例.

"styles": [...]可以用于此的angular.json 路径"projectType": "application"似乎"projectType": "library"也不适用.

在此先感谢您的帮助!


更新:我的项目是使用angular cli v6.0.5启动的,遵循本指南:https://medium.com/@tomsu/how-to-build-a-library-for-angular-apps-4f9b38b0ed11

TL; DR指南:

ng new my-app --style=scss
ng generate library my-library --prefix ml
Run Code Online (Sandbox Code Playgroud)

这是angular 6生成的文件结构:

    my-app
      projects/
        my-library/
          src/
            lib/
              shared/..
              widgets/..
              my-library.component.ts
              my-library.module.ts
            sass/
              _variables.scss
              styles.scss // <<< This is where I want to `@import 'variables';`, and for it to be available in all the components of the "my-library" project.
            public_api.ts
      src/
        app/
          app.module.ts // << imports projects/my-library/lib/my-library.module as "my-library".
        main.ts …
Run Code Online (Sandbox Code Playgroud)

libraries angular-cli angular angular6 angular-cli-v6

23
推荐指数
2
解决办法
6905
查看次数

构建角度库时包含资产

我正在构建一个包含自定义图标字体的库。但是,当我使用 构建我的库时ng build <library-name> --prod,资产文件夹不包含在构建中,这意味着使用生产构建时不会显示图标。

我尝试了多种解决方案,例如添加assets数组angular.json并将资产文件夹复制到创建的 dist 文件夹。

我使用的是 Angular 8,该库是使用 angular-cli 创建的。

我尝试以两种方式包含字体:@import url( '../assets/icon_font.css' );在样式文件之一中使用并../assets/icon_font.css在需要它的组件之一中添加到 styleUrls。(icon_font.css是包含图标字体的 css 文件)

这是我的库目录的布局:

- src
  - lib
    - assets
      - icon_font.css
      - font files
    - component that requires icons
      - style sheet that has @import icon_font.css
    - other components and classes
Run Code Online (Sandbox Code Playgroud)

我希望assets/目录中的 .ttf 和其他字体文件在导出的dist文件夹中可用。

assets angular-cli angular angular-library ng-packagr

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

'compilation' 参数必须是 Compilation 的实例

在我的 Angular 12.0.2 项目上运行“ng build”时出现此错误

./src/polyfills.ts - Error: Module build failed (from ./node_modules/@ngtools/webpack/src/ivy/index.js):
TypeError: The 'compilation' argument must be an instance of Compilation
    at getCompilationHooks (D:\Dev\Git_Merc\mercury\node_modules\webpack\lib\javascript\JavascriptModulesPlugin.js:125:10)
    at D:\Dev\Git_Merc\mercury\node_modules\webpack\lib\javascript\CommonJsChunkFormatPlugin.js:43:19
    at Hook.eval [as call] (eval at create (D:\Dev\Git_Merc\mercury\node_modules\tapable\lib\HookCodeFactory.js:19:10), <anonymous>:7:1)
    at Hook.CALL_DELEGATE [as _call] (D:\Dev\Git_Merc\mercury\node_modules\tapable\lib\Hook.js:14:14)
    at Compiler.newCompilation (D:\Dev\Git_Merc\mercury\node_modules\@angular-devkit\build-angular\node_modules\webpack\lib\Compiler.js:1030:30)
    at D:\Dev\Git_Merc\mercury\node_modules\@angular-devkit\build-angular\node_modules\webpack\lib\Compiler.js:1073:29
    at Hook.eval [as callAsync] (eval at create (D:\Dev\Git_Merc\mercury\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:15:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (D:\Dev\Git_Merc\mercury\node_modules\tapable\lib\Hook.js:18:14)
    at Compiler.compile (D:\Dev\Git_Merc\mercury\node_modules\@angular-devkit\build-angular\node_modules\webpack\lib\Compiler.js:1068:28)
    at Compiler.runAsChild (D:\Dev\Git_Merc\mercury\node_modules\@angular-devkit\build-angular\node_modules\webpack\lib\Compiler.js:520:8)
Run Code Online (Sandbox Code Playgroud)

我一直在谷歌上搜索,但找不到任何可以解决我的问题的东西。我不确定是什么触发了这个。

版本:

Angular CLI: 12.0.2
Node: 14.17.0
Package Manager: npm 7.14.0
OS: win32 …
Run Code Online (Sandbox Code Playgroud)

angular-cli

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