标签: angular8

loadChildren 在 Angular8 中已弃用

我刚刚注意到 Angular 8(即将发布)已经弃用了“字符串类型路由器loadChildren”。(门票

我是否正确理解他们指的是......

const routes = [
  {
    path: 'production',
    loadChildren: './production/production.module#ProductionModule' // <<--this
  }],
Run Code Online (Sandbox Code Playgroud)

要迁移到 Angular 8,解决方案是什么?

在票证中,他们指的是“动态导入”。我是否正确,这是指以下提案:

let module = await import('/modules/my-module.js');
Run Code Online (Sandbox Code Playgroud)

如果我们将来想使用延迟加载,有人可以预览一下路由文件实际上应该是什么样子吗?

lazy-loading dynamic-import angular-load-children angular8

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

Ngrx 效果中的“never”类型不存在属性

我正在使用 Angular 8 和 NGRX 8。我有一个操作:

export const loadEnvironment = createAction(
  LicencingActionTypes.LoadEnvironment,
  props<{environment: Environment}>()
);
Run Code Online (Sandbox Code Playgroud)

以及相应的效果:

 loadEnvironment = createEffect(() => this.actions$.pipe(
    ofType(LicencingActionTypes.LoadEnvironment),
    exhaustMap((action) =>
      this.authService.
      getToken(LicencingEffects.getAuthDetailsForEnvironment(action.environment))
        .pipe(
          switchMap((token) => [
            AuthActions.onLogin({token: token}),
            LicencingActions.onLoadEnvironment({environment: action.environment})
          ]),
          catchError(error => of(AuthActions.onLoginError({error: error})))
        )
    )
  ));
Run Code Online (Sandbox Code Playgroud)

我一直在阅读 NGRX 8 的文档(https://ngrx.io/guide/effects#incorporating-state)。

他们的示例表明您可以只使用操作属性而不强制转换操作的类型:

...
exhaustMap(action =>
        this.authService.login(action.credentials)
...
Run Code Online (Sandbox Code Playgroud)

Webpack 无法编译,并且出现以下错误:

ERROR in src/app/licencing/effects/licencing.effects.ts(20,69): error TS2339: Property 'environment' does not exist on type 'never'.
Run Code Online (Sandbox Code Playgroud)

突出显示错误的代码屏幕截图

我哪里错了?

ngrx-effects angular8

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

storeFreeze 和 ngrx8

我刚刚升级到 ngrx/store 版本 8。我注意到 ng 更新已经删除了所有 storeFreeze 的出现。也将其从metaReducer 中删除。

所以我的问题是 -为什么

在 ngrx 8 中使用 storeFreeze 是否有问题?

在 ngrx8 之前:

import { ActionReducerMap, MetaReducer } from '@ngrx/store';
import { storeFreeze } from 'ngrx-store-freeze';
import * as fromGroupMember from './group-member.reducer';
import * as fromDirectoryForm from './directory-filter-form.reducer';

export const metaReducers: MetaReducer<IState>[] =
(localStorage && localStorage.getItem('production') === 'false') ? [storeFreeze] : [];
Run Code Online (Sandbox Code Playgroud)

后:

import { ActionReducerMap, MetaReducer } from '@ngrx/store';

import * as fromGroupMember from './group-member.reducer';
import * as fromDirectoryForm from …
Run Code Online (Sandbox Code Playgroud)

ngrx angular ngrx-store angular8

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

如何在 Angular 8 中实现嵌套 NG If else 条件

我需要的

        if(field.ajax && field.ajax='Y' && field.multiple&& field.multiple=='Y')
        {

        }
        else if (field.ajax && field.ajax='Y' && field.multiple&& field.multiple=='N'))
        {
        }
        else
        {
        }
Run Code Online (Sandbox Code Playgroud)

2 条件作品

    if(cond)
        {
        code
        }else
        {
        code
        }
Run Code Online (Sandbox Code Playgroud)

这个案例代码有效

   <ng-container *ngIf="field.ajax && field.ajax === 'Y'; else select2ElseBlock">
              <ng-select
              [items]="data"
              multiple="true"
              bindLabel="name"
              [closeOnSelect]="true"
              [loading]="loading"

              [searchable]="true"
              [clearable]="true" 
              (click)="clearModel()"
              (keyup)="changed($event.target.value)">
              </ng-select>
        </ng-container>
       <ng-template #select2ElseBlock>
              <ng-select
              [items]="field.choices.choice"
              multiple="true"
              bindLabel="name"
              [loading]="loading"
              >
              </ng-select>
        </ng-template>
Run Code Online (Sandbox Code Playgroud)

我尝试过多个案例

但这种情况会产生问题

 <ng-container *ngIf="field.ajax && field.ajax === 'Y'  then  select2thenBlock else select2ElseBlock">
          <ng-select
          [items]="data"
          multiple="true"
          bindLabel="name"
          [closeOnSelect]="true"
          [loading]="loading" …
Run Code Online (Sandbox Code Playgroud)

if-statement angular angular8

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

如何从navigateByUrl获取参数?

我使用以下方式进行导航:

this.router.navigateByUrl(item.url);
Run Code Online (Sandbox Code Playgroud)

item.url有价值的地方:

orgtree/1
Run Code Online (Sandbox Code Playgroud)

路线是:

{
        path: "orgtree/:orgstructure",
        component: OrganizationsComponent
      }
Run Code Online (Sandbox Code Playgroud)

我做的内部组件:

 ngOnInit() {
    this.route.paramMap.subscribe(params => {
      console.log(params);

    });
}
Run Code Online (Sandbox Code Playgroud)

为什么我得到空参数?

我也尝试过这个:

this.router.navigate(['/orgtree', 1]);
Run Code Online (Sandbox Code Playgroud)

没有效果

我遇到问题:

路线应该是:

{
        path: "orgtree",
        component: OrganizationsComponent
      }
Run Code Online (Sandbox Code Playgroud)

angular angular8

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

如何在其他scss文件中使用角度材质主题颜色变量

对于学校作业,我们需要使用有角度的材料。我制作了一个自定义主题,名为:weather-theme.scss

\n

该文件中的代码如下:

\n
@import '~@angular/material/theming';\n\n@include mat-core();\n\n// Define the palettes for your theme using the Material Design palettes available in palette.scss\n// (imported above). For each palette, you can optionally specify a default, lighter, and darker\n// hue. Available color palettes: https://material.io/design/color/\n$weather-theme-primary: mat-palette($mat-gray, 800, 700, 600);\n$weather-theme-accent: mat-palette($mat-amber, 800, 700);\n\n// The warn palette is optional (defaults to red).\n$weather-theme-warn: mat-palette($mat-red);\n\n// Create the theme object (a Sass map containing all of the palettes).\n$weather-theme-theme: mat-light-theme(\n    $weather-theme-primary,\n    $weather-theme-accent,\n    $weather-theme-warn\n);\n\n// Include theme styles for core and each …
Run Code Online (Sandbox Code Playgroud)

sass angular-material angular-material2 angular angular8

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

我在实现 ngx-Spinner 8.0.3 时遇到错误

我希望在我的应用程序中实现旋转加载程序。我按照此处给出的流程[ https://www.npmjs.com/package/ngx-spinner ]安装并保存了它。

当我导入并将其添加到“导入”时,我收到以下错误。

未捕获的类型错误:Object(...) 不是 ngx-spinner.js:208 的函数,模块../node_modules/ngx-spinner/fesm5/ngx-spinner.js (ngxspinner.js:210) 在webpack_require (bootstrap ) :78) 在 Module../src/app/app.module.ts (app.component.ts:23) 在webpack_require (bootstrap:78) 在 Module../src/main.ts (main.ts:1)在webpack_require (bootstrap:78) 在 Object.0 (main.ts:12) 在webpack_require (bootstrap:78) 在 checkDeferredModules (bootstrap:45)

npm i ngx-spinner
npm install ngx-spinner --save


aap.module.ts

    import { NgxSpinnerModule } from "ngx-spinner";

    imports: [
        // ...
        NgxSpinnerModule
    ]
Run Code Online (Sandbox Code Playgroud)

我不知道如何摆脱这个错误如果有人可以帮助我。

typescript angular angular8

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

如何修复 NgxMaterialTimepickerContainerComponent 错误找不到组件工厂?

我在项目中使用 ngx-material-timepicker。当我使用最新的 5.2.2 时,出现以下错误

ng:///NgxMaterialTimepickerModule/NgxMaterialTimepickerToggleComponent.n 
gfactory.js:13 ERROR Error: No component factory found for NgxMaterialTimepickerContainerComponent. Did you add it to @NgModule.entryComponents?
    at noComponentFactoryError (:4401/vendor.js:87649)
    at CodegenComponentFactoryResolver.resolveComponentFactory (:4401/vendor.js:87714)
    at DomService.appendTimepickerToBody (:4401/main-exams-exams-module.js:8424)
    at NgxMaterialTimepickerComponent.open (:4401/main-exams-exams-module.js:8848)
    at NgxMaterialTimepickerToggleComponent.open (:4401/main-exams-exams-module.js:8994)
    at Object.eval [as handleEvent] (ng:///NgxMaterialTimepickerModule/NgxMaterialTimepickerToggleComponent.ngfactory.js:19)
    at handleEvent (:4401/vendor.js:103240)
    at callWithDebugContext (:4401/vendor.js:104859)
    at Object.debugHandleEvent [as handleEvent] (:4401/vendor.js:104494)
    at dispatchEvent (:4401/vendor.js:90327)
Run Code Online (Sandbox Code Playgroud)

但当我降级到 4.0.0 版本时,它工作得很好。

// 模块页面

import { NgModule } from '@angular/core';
import { NgxMaterialTimepickerModule } from 'ngx-material-timepicker';
@NgModule({
declarations: [appComponent ],
  imports: [NgxMaterialTimepickerModule]
]
})
Run Code Online (Sandbox Code Playgroud)

html …

datepicker angular8

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

迁移到 Angular 8 后,路由器没有给出导出成员错误

我刚刚迁移到 Angular 8,然后开始收到错误

Module '"../../node_modules/@angular/router/router"' has no exported member 'NoPreloading'.
Run Code Online (Sandbox Code Playgroud)

该错误来自以下行:

import { NoPreloading, RouterModule, Routes } from '@angular/router';
Run Code Online (Sandbox Code Playgroud)

它发生在 的所有成员身上@angular/router。我究竟做错了什么?尽管出现错误,一切仍然正常。

tslint angular angular8

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

我们可以在不通过 CLI 环境开发或生产构建项目的情况下更改 Angular 8 中的根 APIURL吗

我们是否需要使用 prod 和development 构建两次项目,或者是否有其他方法可以更改指向不同服务器的 API 的根 URL,并且无需构建项目即可更改根 URL。

angular angular8

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