标签: angular6

Angular 6"工作区需要在使用前加载." 在尝试生成新组件时

当我使用angular dotnet创建asp.net核心项目时,new命令不会将angular.json文件(角度6)添加到项目中,因此我们无法使用angular cli.如果我手动添加angular.json文件,项目将在下面给出例外!?

Workspace needs to be loaded before it is used. Error: Workspace needs to be loaded before it is used. at Workspace._assertLoaded (D:\NetAngular\node_modules\@angular-devkit\core\src\workspace\workspace.js:59:19) at Workspace.getProjectByPath (D:\NetAngular\node_modules\@angular-devkit\core\src\workspace\workspace.js:103:14) at Object.getPackageManager (D:\NetAngular\node_modules\@angular\cli\utilities\config.js:97:35) at UpdateCommand.runSchematic (D:\NetAngular\node_modules\@angular\cli\models\schematic-command.js:74:38) at UpdateCommand.<anonymous> (D:\NetAngular\node_modules\@angular\cli\commands\update.js:70:25) at Generator.next (<anonymous>) at D:\NetAngular\node_modules\@angular\cli\commands\update.js:7:71 at new Promise (<anonymous>) at __awaiter (D:\NetAngular\node_modules\@angular\cli\commands\update.js:3:12) at UpdateCommand.run (D:\NetAngular\node_modules\@angular\cli\commands\update.js:69:16)
Run Code Online (Sandbox Code Playgroud)

asp.net-core angular angular6

5
推荐指数
3
解决办法
5834
查看次数

HTTP在Angular 6中调用

我将Angular项目更新为Angular 6,并且不知道如何进行http获取请求.这就是我在Angular 5中的表现:

get(chessId: string): Observable<string> {

this.loadingPanelService.text = 'Loading...';
this.loadingPanelService.isLoading = true;

const url = `${this.apiPathService.getbaseUrl()}api/chess/${chessId}/rating`;   

return this.http.get<string>(url)
.catch((error) => {
    console.error('API error: ', error);

    this.loadingPanelService.isLoading = false;
    this.notificationService.showErrorMessage(error.message);

    return Observable.of(null);
  })
  .share()
  .finally(() => {
    this.loadingPanelService.isLoading = false;
  });
Run Code Online (Sandbox Code Playgroud)

这就是我现在正在做的事情.这是应该如何在Angular 6中完成的吗?

...
return this.http.get<string>(url)
.pipe(
  catchError(this.handleError),
  share(),
  finalize(() =>{this.loadingPanelService.isLoading = false})
);

private handleError(error: HttpErrorResponse) {
console.error('API error: ', error);

this.loadingPanelService.isLoading = false;
this.notificationService.showErrorMessage(error.message);

// return an observable with a user-facing error message
return throwError(
  'Something bad happened; …
Run Code Online (Sandbox Code Playgroud)

typescript angular angular-httpclient angular6

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

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
查看次数

解码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
查看次数

角6创建TemplateRef的实例

我有(角度6)组件和TemplateRef<any>类型的输入参数

class TestComponent {
    @Input() tpl: TemplateRef<any>;
    ...
}
Run Code Online (Sandbox Code Playgroud)

现在,我想创建一个测试,但找不到如何在测试中创建模板并将其设置为输入字段的方法。

在我的HTML中,我有类似的模板

<test>
    <ng-template #tpl>
        <div>OLOLO</div>
    </ng-template>
</test>
Run Code Online (Sandbox Code Playgroud)

我需要这样的东西

fixture = TestBed.createComponent(TestComponent);
component = fixture.componentInstance;
component.template = here I need instance of TemplateRef
Run Code Online (Sandbox Code Playgroud)

谢谢

javascript testing typescript angular6

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

离子3 - 画布绘制并不完美,因为鼠标/触摸位置

我创建了一个应用程序,用户可以在画布上绘制任何内容.我已将背景图像添加到画布中.我希望画布覆盖屏幕上的剩余空间.因此,我保持宽度和高度百分比.

问题 - 现在每当我在画布上画一些东西时,它都不会跟随鼠标/触摸屏的准确位置.如果我在下方绘制,它将从触摸中提取近20px.(不确定像素有多少但是我的假设)

请仔细阅读下面的代码.

1. HTML

<ion-row>
      <canvas no-bounce 
      (touchstart)='handleStart($event)' (touchmove)='handleMove($event)' (click)="removeSelectedTxt()"
      [ngStyle]="{'background': 'url(' + selectedImage + ') no-repeat center center fixed', '-webkit-background-size': 'contain',
      '-moz-background-size': 'contain',
      '-o-background-size': 'contain',
      'background-size': 'contain',
      'width': '98%',
      'height': '65%'}" #canvas ></canvas>
  </ion-row>
Run Code Online (Sandbox Code Playgroud)

2. CSS

canvas {
      display: block;
      border: 1px solid #000;
      position: fixed;
      top: 10%;
      left: 1%;
    }
Run Code Online (Sandbox Code Playgroud)

3. TS文件

    import { Component, ViewChild,  ElementRef} from '@angular/core';

     @ViewChild('canvas') public canvas: ElementRef;

    this.canvasElement = this.canvas.nativeElement;

handleStart(ev){

        this.lastX = ev.touches[0].pageX;
        this.lastY = ev.touches[0].pageY;
    }

    handleMove(ev){ …
Run Code Online (Sandbox Code Playgroud)

javascript html5-canvas ionic3 angular angular6

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

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
查看次数

Angular 6每X秒运行一次功能

我有一个函数叫做

opensnack(text) { ... };

这将使用给定的文本输入打开一个有角度的材质小吃栏。

我想做的就是每10秒调用一次此函数。

我应该怎么做?

typescript angular angular6

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