小编mal*_*awi的帖子

找不到模块“@angular/common/http”

我已将 npm 升级到最新版本。我的 Visual Studio 应用程序中的 npm 文件夹读取 v6.0.3,而我的 package.json 文件也对应于此版本 6.0.3。

但是每当我运行我的应用程序时,我都会收到错误“无法在浏览器上找到模块”

请参阅错误图片

我相信 HttpClient 在 3x 以上的版本中使用,但显然安装了更高的版本。

应用程序模块.ts

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
import { RouterModule } from '@angular/router';

import { AppComponent } from './components/app/app.component';
import { NavMenuComponent } from './components/navmenu/navmenu.component';
import { HomeComponent } from './components/home/home.component';
import { FetchDataComponent } from './components/fetchdata/fetchdata.component';
import { CounterComponent } from './components/counter/counter.component';
import …
Run Code Online (Sandbox Code Playgroud)

npm package.json angular

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

禁用表单时,响应式表单有效属性返回 false

我有这个简单的表单并用于创建和更新案例,因此对于创建案例,用户将输入数据并基于验证器我将获得form.valid(真,假)。在更新的情况下,我只是从 api 获取数据并将此值设置为表单并使表单禁用;

this.form = fb.group({
  name: ['', Validators.required],
  lastName: ['', Validators.required],
  address: [''],
});
Run Code Online (Sandbox Code Playgroud)

因此,当我禁用表单时,有效值始终为false

 ngOnInit() {
    this.form.patchValue({
      name: 'name',
      lastName: 'Last Name'
    });

    this.form.disable();
  }
Run Code Online (Sandbox Code Playgroud)

堆叠闪电战示例

typescript angular angular-reactive-forms

6
推荐指数
2
解决办法
9362
查看次数

NullInjectorError: 没有 String 的提供者!在角 6

父类

import { BadRequestError } from './../common/bad-request-error';
import { NotFoundError } from './../common/not-found-error';
import { AppError } from './../common/app-error';
import { Http } from '@angular/http';
import { Injectable, OnInit } from '@angular/core';
import { catchError } from 'rxjs/operators';
import { throwError} from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class DataService {
  constructor(private url: string , private http: Http) {
 }

getAll() {
 return this.http.get(this.url).pipe(catchError(this.handleError));
}

delete(id) {
  return this.http.delete(this.url + '/' + id)
   .pipe(
    catchError(this.handleError));
 }

update(resource) {
  return this.http.patch(this.url …
Run Code Online (Sandbox Code Playgroud)

dependency-injection angular

6
推荐指数
1
解决办法
5722
查看次数

如何使用angular 5使用blob函数下载文件

使用Blob功能下载任何文件类型

private saveAsBlob(data: any) {
 const blob = new Blob([data._body],
 const file = new File([blob], 'image.png',
 FileSaver.saveAs(file);
}
Run Code Online (Sandbox Code Playgroud)

typescript angular

6
推荐指数
2
解决办法
3634
查看次数

复杂的Typescript与对象的接口

我有一个接口定义为:

export interface Address {
    addressType: {
        house?: {
            streetAddress: string,
            city: string,
            zip: string,
        },
        apartment?: {
            streetAddress: "",
            unitNumber: "",
            city: "",
            zip: "",
            buildingName?: "",
        },
    }
    instructions?: string;
}
Run Code Online (Sandbox Code Playgroud)

然后在我的组件的Typescript文件中,我定义了一个房屋地址:

address: Address;

constructor() {

    this.address.addressType = {
      house: {
        streetAddress: "1 test",
        city: "test city",
        zip: "92222",
      }
    }        
    console.log(this.address);
}
Run Code Online (Sandbox Code Playgroud)

虽然当我将地址记录到控制台时,我得到:

Uncaught (in promise): TypeError: Cannot set property 'addressType' of undefined
Run Code Online (Sandbox Code Playgroud)

我以为我在构造函数中设置了addressType.有没有更有效的方法来做我正在做的事情?

typescript angular

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

为自定义属性实现双向数据绑定

我在primeng组件中看到对某些属性使用类似ngModel(双向数据绑定)样式的东西

[(selection)]="selectedItem";
Run Code Online (Sandbox Code Playgroud)

看起来像

@Input() selection;
@Output() selection:EventEmitter<any> = new EventEmitter<any>();
Run Code Online (Sandbox Code Playgroud)

我如何实现这样的东西,并且有可能做更多的事情而不是像

 <component-a  [(selection)]="selectedItem"  [(data)]="selectedData"></component-a>
Run Code Online (Sandbox Code Playgroud)

primeng angular

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

如何检测 Angular 何时将元素附加到 DOM?

有一个组件:

<my-component></my-component>

它的组件接收一串数字作为@Input

<my-component [data]="numbers$ | async"></my-component>

在组件内部我们更新模型:

@Component({...})
class MyComponent {

  numbers: number[] = [];

  @Input
  set data(numbers: number[]) {
      this.numbers = numbers;
  }

  constructor() {}

  myCallback() { }
}
Run Code Online (Sandbox Code Playgroud)

然后渲染数字列表,如下所示:

<ul>
 <li *ngFor="number of numbers">{{number}}</li>
</ul>
Run Code Online (Sandbox Code Playgroud)

如何检测已经*ngFor渲染了所有元素?myCallback元素添加到 DOM 后如何调用回调函数?

angular

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

Angular 在 docker 中不起作用,因为它找不到模块 @angular-devkit/build-angular

我尝试忽略 node_modules 但仍然对我不起作用,即使在忽略 node_modules 之后我仍然面临同样的错误

yaml文件:

version: '3.5'

services:
    angular-docker:
        hostname: localhost
        container_name: angular-docker
        build: ./angular-doc
        volumes:
          - './angular-doc:/usr/src/app/'
        ports:
          - '4200:4200'
Run Code Online (Sandbox Code Playgroud)

泊坞窗文件:

FROM node:10.12.0

RUN mkdir usr/src/app

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install -g @angular/cli@latest

COPY . .

EXPOSE 4200

CMD ng serve --host 0.0.0.0
Run Code Online (Sandbox Code Playgroud)

jasmine asp.net-mvc-4 protractor cucumberjs angular

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

Angular 将服务注入基类但不在子类中,并在子类中使用父服务

使用 Angular 7 和 Typescript:我有一个使用大量服务和子类(大约 40 个子类)的基类,我不想在所有子类构造函数中添加这些服务并将它们传递给super()但我仍然需要在所有子类中使用这些服务。


export class parentTool {

    constructor(type: string, public service1: Service1, public service2: Service2,public service3: Service3, public service4: Service4){}
}

export class ChildTool1 extends parentTool {

    constructor(public service1: Service1, public service2: Service2,public service3: Service3, public service4: Service4) {

        super("tool1", service1, service2, service3, service4);
    }
}

export class ChildTool2 extends parentTool {

    constructor(public service1: Service1, public service2: Service2,public service3: Service3, public service4: Service4) {

        super("tool2", service1, service2, service3, service4);
    }
}
Run Code Online (Sandbox Code Playgroud)

typescript angular angular7

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

在 Angular 中单击编辑时内联编辑表格行

我有一个表,其中数据正在填充。每行都有一个编辑链接。我只想在单击编辑链接时编辑特定行。现在它的'显示所有行的编辑选项。

我还想在单击编辑时在输入框中显示文本。

这是我的代码。

<tr *ngFor="let row of backendData.report"  class="hover-highlight">

          <td class="benchmark_name">
             {{row.name}}
          </td>
          <td>
            {{row.value}}
          </td>
          <td>
            {{row.description}}
          </td>
          <td>
              <button *ngIf="enableEdit" (click)="enableEdit=false" class="btn page-secondary-action-btn" ng-click="cancel()">Cancel</button>
              <button *ngIf="enableEdit" id="saveBtn" class="btn page-primary-action-btn" (click)="saveSegment()" type="submit">Save</button>
              <a class="table-row-action edit-action" *ngIf="!enableEdit" (click)="enableEdit = true">
          <i class="fa fa-pencil" uib-tooltip="Edit" tooltip-trigger="mouseenter" tooltip-append-to-body="true" tooltip-placement="left"></i>
        </a>
          </td>
          <td>

          </td>
        </tr>
Run Code Online (Sandbox Code Playgroud)

我当前的输出看起来像这样

在此处输入图片说明

在此处输入图片说明

html javascript angular angular5

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