标签: angular-cli

Angular 2 - 子路由加载父组件

我试图让我的路由在我的Angular 2应用程序中工作.

这是我在app.routes.ts文件中使用的代码

export const ROUTES: Routes = [
  { path: '',      component: PublicComponent, data: { title: 'Heroes List' } },
  { path: 'home',  component: PublicComponent },
  { path: 'admin',  component: PrivateComponent, children: [
    { path: '', component: PrivateComponent },
    { path: 'account-settings', component: AccountSettingsComponent, children: [
      { path: '', component: UserInformationComponent},
      { path: 'user-information', component: UserInformationComponent},
      { path: 'companys-information', component: CompanysInformationComponent}
    ] },
  ] },
  { path: '**',    component: NoContentComponent },
];
Run Code Online (Sandbox Code Playgroud)

每当我尝试导航到其中一个子路由时,它就会加载父路由.

所以我要说比较一下: -

http://localhost:4200/#/admin

它会引入正确的组件PrivateComponent. …

routing angular-cli angular

5
推荐指数
2
解决办法
6216
查看次数

由Lighthouse测量的Hello World Angular CLI(为什么慢而且巨大?)

是否需要对Angular CLI Hello World应用优化,还是这是一个有效的"性能"结果?

在将Lighthouse应用于我们的live angular 4项目时,我们将与Angular CLI Hello World进行了比较.

从控制台:

npm install -g @angular/cli
ng new my-dream-app
cd my-dream-app
ng serve --prod
Run Code Online (Sandbox Code Playgroud)

在Chrome中 - > F12 - >审核 - >运行灯塔.

  • 表现为39/100.
  • 第一个有意义的油漆是15,250毫秒
  • 感知速度指数:15,248(目标:<1,250)
  • 拥有巨大的网络负载:总大小为2,453 KB(目标:<1,600 KB)

更新1

感谢@Moshe,使用:

ng serve --prod --build-optimizer
Run Code Online (Sandbox Code Playgroud)

提供以下内容: - 性能为96/100. - First Meaningful Paint是2,040ms - 感知速度指数:2,054(目标:<1,250); 等级92/100

最终难以形成一个单一,简明的问题.我理解 ng serve 不是为了生产使用,即使使用ags ..但这允许我在发布之前在我的localhost上进行测试.

lighthouse angular-cli angular

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

创建Leaflet Extended Control时如何利用Angular 4组件?

我现在与Leaflet和Angular CLI一起工作了几个星期,涉及一个涉及地理地图和室内地图(Leaflet自定义地图)的项目。

该应用程序在概念上非常简单。我必须以简单的位置树表的形式向用户提供室内位置(例如房间)的列表,在其中,用户单击时,必须调用新的室内地图。另外,我必须制作一个自定义搜索框,其中包含一些过滤选项,用于搜索结构化数据集并以小叶标记的形式在地图上绘制数据。

我的问题是:考虑到应用程序的性质和我正在使用的技术(Leaflet库和Angular CLI ),实现上述2个控件(位置树和搜索框)的最佳方法是什么?(角4.x))?

从我的角度来看,我现在可以看到两个选项:

1)使用Leaflet L.control.extended(negative(-):创建控件(位置树和带有过滤器的搜索框):在我看来,我必须按顺序在L.control.extended'onAdd'函数中静态键入html 创建控件->没有Angular 4模板引擎的优势)

2)以Angular 4方式使用Angular 4 Component的模板创建控件,而忽略了Leaflet L.control.extended的存在 (否定:在我看来,此选项不必要地使应用程序复杂化+直观上似乎是错误的,因为Leaflet扩展控件似乎对于这类问题“天生”)

如果能以某种方式将Angular组件动态嵌套在Leaflet自定义控件中,那就太好了。有什么建议么?

maps dynamic leaflet angular-leaflet-directive angular-cli

5
推荐指数
0
解决办法
303
查看次数

在angular \ cli中使用ng2-ckeditor

请不要将此问题标记为已解决,因为stackoverflow上没有可用的解决方案可以解决我的问题,我正在尝试将ng2-ckeditor ckeditor 集成到现有的angular 4项目中。我尝试遵循此处描述的步骤,但徒劳无功。我在git和stackoverflow上找到了不同的讨论,但对我没有用。

我进行如下

在我的索引文件中引用了以下js文件

1 <script src="https://cdn.ckeditor.com/4.5.11/full/ckeditor.js"></script>
2 <script src="config.js"></script>
Run Code Online (Sandbox Code Playgroud)

在我的app.module.ts中导入模块

import{CKEditorModule} from "ng2-ckeditor"; 
.
.
.;

imports: [
    BrowserModule,
    AppRoutingModule,
  .
  .
  .,
    CKEditorModule,
  ],
Run Code Online (Sandbox Code Playgroud)

但是当我尝试在我的应用程序中使用ckeditor代码时

<ckeditor [(ngModel)]="description" > </ckeditor>
Run Code Online (Sandbox Code Playgroud)

它被标记为未知元素,我得到以下文本提示

[Angular]
'ckeditor' is not a known element:
1. If 'ckeditor' is an Angular component, then verify that it is part of this module.
2. To allow any element add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component.
Run Code Online (Sandbox Code Playgroud)

当我运行ng serve命令时,编译成功,但未显示任何内容,并且出现以下控制台错误

Uncaught Error: Template parse errors: …
Run Code Online (Sandbox Code Playgroud)

angular-cli ng-ckeditor angular

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

Angular CLI错误路径和代码EEXIST

我首先安装了npm并确保它是最新的.然后我尝试安装角度,但我遇到了错误

~ kode$ sudo npm install -g @angular/cli

Password:

npm WARN ajv-keywords@3.1.0 requires a peer of ajv@^6.0.0 but none is installed. You must install peer dependencies yourself.

npm ERR! path /usr/local/bin/ng

npm ERR! code EEXIST

npm ERR! Refusing to delete /usr/local/bin/ng: ../lib/node_modules/angular-cli/bin/ng symlink target is not controlled by npm /usr/local/bin

npm ERR! File exists: /usr/local/bin/ng

npm ERR! Move it away, and try again.


npm ERR! A complete log of this run can be found in:

npm ERR!     /Users/kode/.npm/_logs/2018-02-15T13_10_57_836Z-debug.log
Run Code Online (Sandbox Code Playgroud)

我不明白它是如何告诉我文件已经存在但当我运行任何ng命令时它告诉我:

ng: …
Run Code Online (Sandbox Code Playgroud)

command-line-interface angular-cli angular

5
推荐指数
2
解决办法
7749
查看次数

Angular 5循环相关性:组件中的组件

我目前在一个项目中,我们有一个动态的“表单” /内容模型,该模型具有一个包含字段和占位符的模块,占位符可以包含更多模块,从而为我们提供了递归/灵活的数据模型。

现在进行渲染,我们创建了一个用于渲染模块的组件,针对不同的字段类型进行了动态渲染,然后创建了一个for循环来渲染占位符,这是它自己的组件。

我得到的循环依赖是 module.component -> placeholder.component -> module.component

可以在以下plunkr中找到对此的快速设置:https ://plnkr.co/edit/ieV9rjJ8MZLzFpzPaj3L

运行ng serve没有错误,但ng build --prod确实

WARNING in Circular dependency detected:
src/app/module.component.ngfactory.js -> 
src/app/placeholder.component.ngfactory.js -> 
src/app/module.component.ngfactory.js
Run Code Online (Sandbox Code Playgroud)

我猜这是因为ng build --prodAOT是否建立并且循环依赖关系在HTML中。

但是代码运行良好,真正的问题是这是否被认为是不良的实现模式?我不确定如何解决该问题。

javascript angular-cli angular angular5

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

如何在Angular-CLI项目中覆盖node_module错误输入?

我有一个错误的node_module(angularfire2),它没有使用另一个node_module(@ firebase)中的新版本更新.

我正在尝试让tsconfig.json帮助我为它设置一个路径别名,以便将其重新路由以解析为在src中编写的调整文件而不是@ firebase的node_modules中的不兼容的输入文件作为临时修复.

我知道我可以降级(@firebase)node_module以使其兼容.然而,这个问题并不是要让它发挥作用.我只是想弄清楚如何能够覆盖node_module坏的打字.

我正在使用Angular的cli项目,希望我不需要弹出webpack来控制它.

我从这篇文章中了解到,我覆盖了@types文件夹中的打字.

但是我仍然无法在node_module本身中使用index.d.ts覆盖打字输入.

例如(来自angularfire2)

import { FirebaseApp as FBApp } from '@firebase/app-types';
Run Code Online (Sandbox Code Playgroud)

我想@firebase/app-types在我的tsconfig.json中创建一个别名,以便angularfire2可以查看src/types-overwrite/@firebase/app-types.

我有以下tsconfig.json但它仍然不会正确执行别名,并仍将解析为不兼容的node_module的输入文件而不是src中的文件.

我的tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types",
      "src/types-overwrite"
    ],
    "paths": {
      "@firebase/app-types": ["src/types-overwrite/@firebase/app-types"]
    },
    "lib": [
      "es2017",
      "dom"
    ]
  },
  "include": [
    "node_modules/angularfire2",
  ]
}
Run Code Online (Sandbox Code Playgroud)

如何在Angular-CLI项目的node_module中覆盖index.d.ts键入文件,或者如何让我的tsconfig.json工作?

更新:

我添加了一个存储库来展示问题:

  • '@ firebase/app-types'有额外的日志记录用于记录目的(from_node_modules或from_src)(因此node_modules已包含在存储库中)

网址:https://github.com/Jonathan002/resolve-typing

typescript tsconfig angular-cli typescript-typings

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

错误解析'... ge-2.2.1.tgz"}附近的JSON输入意外结束,"engin"

命令:

npm install -g @angular/cli@latest
Run Code Online (Sandbox Code Playgroud)

例外:

详细信息堆栈语法错误:在'... ge-2.2.1.tgz"}附近解析JSON输入时出现意外结束,"在jSON.parse()中运行'169详细堆栈',在parseJson处于169详细堆栈(C:\ Program Files \nodejs \node_modules \npm \node_modules\pacote \node_modules\make-fetch-happen \node_modules \node-fetch-npm \node_modules\json-parse-better-errors\index.js:7:17)169在consumeBody处的详细堆栈. call.then.buffer(C:\ Program Files \nodejs \node_modules \npm \node_modules\pacote \node_modules\make-fetch-happen \node_modules \node-fetch-npm\src\body.js:96:50)169 verbose在process._tickCallback处于169详细堆栈的堆栈(内部/进程/ next_tick.js:188:7)


寻求帮助和支持.谢谢

angular-cli angular

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

Angular CLI 6自定义Webpack SCSS加载器

我正在尝试编写一个自定义Webpack模块,以用cli 6覆盖或扩展角度为6的当前SCSS构建,目的是能够传递“品牌”并将其与任何替代匹配,例如“ somemodule /'brand' /filename.override.scss”并替换父文件夹“ somemodule / filename.scss”中的文件,但我没有任何进展。

设置:@ angular / cli“:” 6.2.2“,带有@ angular-builders / custom-webpack”:“ ^ 2.4.1”

我已经更新了项目构建,以反映出我正在使用自定义Webpack,以及覆盖/扩展的位置

     "build": {
      "builder": "@angular-builders/custom-webpack:browser",
      "options": {
        "customWebpackConfig": {
          "path": "./extra-webpack.config.js"
        },
Run Code Online (Sandbox Code Playgroud)

我的extra-webpack.config.js看起来像这样,只是我在许多网站上看到的一种基本的hello世界风格

module.exports = {
    module:{
        rules: [{
            test: /\.scss$/,
            use: [{
                loader: "style-loader"
            }, {
                loader: "css-loader"
            }, {
                loader: "sass-loader",
                options: {
                    includePaths: ["src"]
                }
            }]
        }]
    }
};
Run Code Online (Sandbox Code Playgroud)

但是用这个来运行我的构建

ng run websitename:build
Run Code Online (Sandbox Code Playgroud)

引发此错误

    Module build failed (from ./node_modules/sass- 
Run Code Online (Sandbox Code Playgroud)

loader / lib / loader.js):

^                                                                                        
  Invalid CSS after "": …
Run Code Online (Sandbox Code Playgroud)

sass webpack angular-cli angular-cli-v6

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

stylePreprocessorOptions在@ Angular / cli 7上不起作用

因此,我正在尝试“ whitelabelyze”我的应用程序,以便为多个客户端提供多种设计选项。在组件的scss内部,我需要加载一个'_variables.scss',该文件将位于此'themes'文件夹下,其结构如下:

/
- themes
-- client-1
--- _variables.scss
-- client-2
--- _variables.scss
Run Code Online (Sandbox Code Playgroud)

在我的angular.json内部,我有以下配置:

"projects": {
  "client-1": {
     ...
     "architect": {
       "build": {
         ...
         "options": {
           ...
           "stylePreprocessorOptions": {
             "includePaths": [
               "themes/client-1"
             ]
           },
           "styles": [
             "src/styles.scss",
           ]
           ...
         }
         ...
       }
     },

     "client-2": {
     ...
     "architect": {
       "build": {
         ...
         "options": {
           ...
           "stylePreprocessorOptions": {
             "includePaths": [
               "themes/client-2"
             ]
           },
           "styles": [
             "src/styles.scss",
           ]
           ...
         }
         ...
       }
     }
  }
Run Code Online (Sandbox Code Playgroud)

根据文档,我做对了,但是我的scss文件没有正确加载文件“变量”。这是我的scss文件上的导入:

@import "variables";
Run Code Online (Sandbox Code Playgroud)

这是发生的错误:

ERROR in ./src/app/app.component.scss …
Run Code Online (Sandbox Code Playgroud)

sass angular-cli angular

5
推荐指数
2
解决办法
7513
查看次数