标签: angular6

从Angular 5升级到Angular 6后:当前文档没有doctype

我刚刚将Angular 5项目升级到Angular 6.升级后它编译得很好,但网站显示空白.在控制台中,我得到:

当前文档没有doctype.这可能会导致某些Angular Material组件无法按预期运行.push ../ node_modules/@angular/material/esm5/core.es5.js.MatCommonModule._checkDoctypeIsDefined @core.es5.js:122 MatCommonModule @ core.es5.js:92 _createClass @core.js:8116 createProviderInstance $ 1 @ core .js:8088 initNgModule @ core.js:8024 NgModuleRef @ core.js:8747 createNgModuleRef @ core.js:8736 debugCreateNgModuleRef @ core.js:10561 push ../ node_modules/@angular/core/fesm5/core.js.NgModuleFactory_ .create @ core.js:11263(匿名)@ core.js:4161 push ../ node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke @ zone.js:388 onInvoke @ core.js:3671 push ../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke @ zone.js:387 push ../ node_modules/zone.js/dist/zone.js.Zone.run @ zone.js:138 push ../node_modules/@angular/core/fesm5/core.js.NgZone.run @core.js:3585 push ../ node_modules/@angular/core/fesm5/core.js.PlatformRef.bootstrapModuleFactory @ core.js: 4159(匿名)@ core.js:4200 push ../ node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke @ zone.js:388 push ../ node_modules/zone.js/dist/zone.js.Zone.run @ zone.js:138(匿名)@ zone.js:872 …

npm typescript angular-material angular angular6

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

Angular 6 - HTTP响应200在订阅中为空

我有以下http.service.ts用于调用/loginAPI的Angular .

login(user: User) {
    console.log("logging in");
    console.log(JSON.stringify(user));
    this.http
        .post<any>(this.loginURL, user, httpOptions)
        .subscribe(
            res => console.log('response : ' + res),
            err => console.log('error : ' + err))
}
Run Code Online (Sandbox Code Playgroud)

这是一个非常标准的POST电话,但它总是返回null,我无法理解.这是NetworkGoogle Chrome的标签信息

在此输入图像描述

Chrome的Console信息

在此输入图像描述

我无法理解为什么回应null.即使我没有有效载荷,它至少应该headers可用吗?

post angular angular-httpclient angular6

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

Angular 6-无法使用ngModel

我正在使用Angular6。我想像这样使用ngModel:

<input type="text" [(ngModel)]="textValue">
Run Code Online (Sandbox Code Playgroud)

在html上,我收到以下错误:

Can't bind to 'ngModel' since it isn't a known property of 'input'
Run Code Online (Sandbox Code Playgroud)

当我搜索时,我知道必须导入FormsModule。因此,在我的json包中,我添加了如下的角度形式:

"dependencies": {
        "@angular/core": "^6.0.4",
        "@angular/forms": "^0.2.0"
   ...
Run Code Online (Sandbox Code Playgroud)

是否安装了npm,然后在app.module上,

我在导入中添加了FormsModule,

imports: [
        CommonModule,
        FormsModule,
    ],
Run Code Online (Sandbox Code Playgroud)

但是当我尝试从angular / forms导入FormsModule时,

import { FormsModule } from '@angular/forms';
Run Code Online (Sandbox Code Playgroud)

它说:

Module '"PATH-TO-PROJECT/node_modules/@angular/forms/index"' has no exported member 'FormsModule'
Run Code Online (Sandbox Code Playgroud)

如何使mgModel在Angular 6上运行?

angular angular6

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

ngx-translate在延迟加载的模块中没有显示任何文本

我们在我们的应用程序中使用Angular 6.我们最近开始准备我们的应用程序来进行延迟加载.应用程序有多个延迟加载的路由.我们希望为所有路由使用单个语言文件(不需要将其分成块.但是在bootstrap上加载所有翻译).

我尝试的第一件事就是在AppModule(forRoot)中导入和配置ngx-translate而不是其他地方.为此,我使用以下代码为TranslateModule创建了一个配置文件:

import {
    MissingTranslationHandler, MissingTranslationHandlerParams, TranslateLoader,
    TranslateModuleConfig
} from '@ngx-translate/core';
import {HttpClient} from '@angular/common/http';
import {TranslateHttpLoader} from '@ngx-translate/http-loader';

export class MyMissingTranslationHandler implements MissingTranslationHandler {
    handle(params: MissingTranslationHandlerParams): string {
        return '';
    }
}

export function createTranslateLoader(http: HttpClient): TranslateHttpLoader {
    return new TranslateHttpLoader(http, '/l10n/', '.json');
}

export const TRANSLATE_MODULE_CONFIG: TranslateModuleConfig = {
    loader: {
        provide: TranslateLoader,
        useFactory: (createTranslateLoader),
        deps: [HttpClient]
    },
    missingTranslationHandler: {provide: MissingTranslationHandler, useClass: MyMissingTranslationHandler},
};
Run Code Online (Sandbox Code Playgroud)

这仅适用于急切加载的路线.对于延迟加载的所有文本都是空的.

然后我尝试forChild()在延迟加载的模块中使用与TranslateModule相同配置的方法(因为它在这里写 - ngx-translate).结果相同.我还尝试简单地将TranslateModule导入到延迟加载的模块中,而不提供任何配置.

这两种方式都不奏效.延迟加载的路由中的所有文本字段都是空的.

有没有人有类似的问题?我在网上搜索但找不到任何具体的解决方案.如何将来自同一文件的翻译正确应用于延迟加载的模块?

lazy-loading ngx-translate angular angular6

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

Angular 6-导入带有子路由的库/ npm模块时正确路由

我已按照本指南构建了Angular 6库模块,并在库中运行了一个虚拟应用程序,因此我可以在开发过程中导入和测试模块。

我从库中导入的库模块具有子路由。我认为这是此问题的根本原因。双关打算。库模块的路由模块如下所示:

// Library Module routing
const routes: Routes = [{
    path: '',
    children: [
        { path: '', component: LoginFormComponent },
        { path: 'forgot-password', component: ForgotPasswordFormComponent }
    ]
}];

@NgModule({
    imports: [ RouterModule.forChild(routes) ],
    exports: [ RouterModule ]
})
export class LoginRoutingModule {}
Run Code Online (Sandbox Code Playgroud)

在我的虚拟应用程序中,我有一个模块模块,由应用程序路由模块延迟加载:

// Dummy app root routing
const appRoutes: Routes = [
    {
        path: '',
        children:  [{
            path: 'modules',
            loadChildren: './modules/modules.module#ModulesModule'
        }]
    },
    { path: '**', redirectTo: '' }
];

@NgModule({
    imports: [RouterModule.forRoot(appRoutes)],
    exports: [RouterModule] …
Run Code Online (Sandbox Code Playgroud)

routes node-modules angular ng-packagr angular6

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

当我在HttpInterceptor类中注入使用HttpClient的服务时,Angular 6进入循环依赖的无限循环

我已经在不同的Angular版本中多次发现此问题,但是有多个消息来源说它已经得到解决,例如,关于Stackoverflow的另一个类似问题是有这个答案,它说它已在Angular 5.2中解决,在Github上还有其他问题在说在6.0.2中解决,我正在使用Angular 6.0.3,但是每当我尝试在HttpInterceptor类中注入使用HttpClient的服务时(仍然会收到一个问题)(如果在该请求中接收到jwt,则应该在请求中添加jwt令牌)服务)

我没有收到具有周期性依赖关系的警告或错误,请在浏览器控制台中看到数千个Interceptor正在调用服务的请求,反之亦然。

解决此问题的正确方法是什么?(最好不将jwt存储在本地存储中)

(即使用拦截器并从服务中获取jwt)

我的服务:

 ....
 // only showing parts that matter, HttpClient is injected here
 // to be used in calling the API services

  constructor(public http: HttpClient, private route: ActivatedRoute,
 public translate: TranslateService, private router: Router,
 public snackBar: MatSnackBar, private notification: NotificationService) {

//
Run Code Online (Sandbox Code Playgroud)

我的HttpInterceptor:

import { Observable } from 'rxjs';
import { Location } from '@angular/common';
import { Injectable, Injector } from '@angular/core';
import { HttpInterceptor } from '@angular/common/http';
import { …
Run Code Online (Sandbox Code Playgroud)

javascript cyclic-dependency angular-http-interceptors angular angular6

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

解码Angular 6中的html实体

我正在寻找可以在角度6中解码我的html实体的库

我试图找到一些东西,并且在angular 2中找到了一个名为trustashtml的函数,但是我不认为它适用于6版本。

在下面您可以在html模板中找到我的代码:

 <div [innerHTML]="post.body | markdown"></div>
Run Code Online (Sandbox Code Playgroud)

我的字段发布api返回本地html是这样的:

<p style="margin: 1em 0px; font-size: 18px; line-height: 1.5; font-family: Lato, sans-serif;">Hey Android users! Since launching the Grammarly Keyboard for iOS, we&rsquo;ve heard from </p>
Run Code Online (Sandbox Code Playgroud)

任何的想法 ?

angular6

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

NullInjectorError:Angular 6中没有AnimationBuilder的提供程序

您好,我使用Angular 6以及材料设计

我已经包括了材料和动画的所有依赖关系

在编译时没有给出错误,但是在浏览器渲染时出现了以下错误在此处输入图片说明

我已经导入了所有必需的依赖项

import { animate, AnimationBuilder, AnimationPlayer, style } from '@angular/animations';

AppComponent.html:40 ERROR Error: taticInjectorError(AppBrowserModule)[FuseSidebarComponent -> AnimationBuilder]: 
 StaticInjectorError(Platform: core)[FuseSidebarComponent -> AnimationBuilder]: 
NullInjectorError: No provider for AnimationBuilder!
at NullInjector.push../node_modules/@angular/core/fesm5/core.js.NullInjector.get (core.js:1034)
at resolveToken (core.js:1271)
at tryResolveToken (core.js:1216)
at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:1113)
at resolveToken (core.js:1271)
at tryResolveToken (core.js:1216)
at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:1113)
at resolveNgModuleDep (core.js:8161)
at NgModuleRef_.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get (core.js:8849)
at resolveDep (core.js:9214)



import { animate, AnimationBuilder, AnimationPlayer, style } from '@angular/animations';
import { DOCUMENT } from '@angular/common';
@Injectable({
providedIn: 'root'
})
export class …
Run Code Online (Sandbox Code Playgroud)

angular angular-animations angular6

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

SSR在Angular中采用了错误的环境

我有适用于SSR的Angular 6应用程序.我注意到它在server.js中的SSR上需要一次错误的environmanet变量文件(environment.ts)(没有SSR时没有发生)

这是编译server.js的和平, var environment_1 = __webpack_require__(/*! ../../../../environments/environment */ "./src/environments/environment.ts");这很自然,因为编译浏览器时angular.json交换文件

 "fileReplacements": [
                            {
                                "replace": "src/environments/environment.ts",
                                "with": "src/environments/environment.prod.ts"
                            }
                        ]
Run Code Online (Sandbox Code Playgroud)

然而,一旦webpack编译服务器,它只需要enironment.ts这是dev配置

/***/ "./src/environments/environment.ts":
/*!*****************************************!*\
  !*** ./src/environments/environment.ts ***!
  \*****************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";

// The file contents for the current environment will overwrite these during build.
// The build system defaults to the dev environment which uses `environment.ts`, but if you do
// `ng build --env=prod` then `environment.prod.ts` will be used instead. …
Run Code Online (Sandbox Code Playgroud)

environment-variables server-side-rendering ssr angular angular6

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

NgRx Redux devtools不显示存储和状态详细信息,即使applicaton运行良好

我正在使用以下示例应用程序来学习angular + ngrx。 APM示例NgRx应用

我已经安装了Redux firefox扩展。但是,每当我运行/重新加载应用程序时,“ redux”选项卡都会显示“找不到存储”消息。该应用程序按预期方式工作(能够保留状态)。我能够调度动作,在化简器中进行处理等。请帮助..我被困在很长一段时间。

redux ngrx redux-devtools-extension angular6

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