小编Jac*_*amm的帖子

组件是2个模块声明的一部分

我尝试构建一个离子2应用程序.当我在浏览器中使用离子服务器尝试应用程序或在模拟器上启动它时,一切正常.

但是当我每次尝试构建错误时

ionic-app-script tast: "build"
Error Type AddEvent in "PATH"/add.event.ts is part of the declarations of 2 modules: AppModule in "PATH"/app.modules.ts and AddEvent in "PATH"/add-event.module.ts.
Please consider moving AddEvent in "PATH"/add-event.ts to a higher module that imports AppModule in "PATH"/app.module.ts and AddEventModule.
You can also creat a new NgModule that exports and includes AddEvent then import that NgModule in AppModule and AddEventModule
Run Code Online (Sandbox Code Playgroud)

我的AppModule是

import { NgModule, ErrorHandler } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { IonicApp, IonicModule, …
Run Code Online (Sandbox Code Playgroud)

declaration build ionic2 ionic3 angular

100
推荐指数
5
解决办法
13万
查看次数

如何在角4反应形式中找到无效控件

我在Angular中有一个反应形式,如下所示:

this.AddCustomerForm = this.formBuilder.group({
    Firstname: ['', Validators.required],
    Lastname: ['', Validators.required],
    Email: ['', Validators.required, Validators.pattern(this.EMAIL_REGEX)],
    Picture: [''],
    Username: ['', Validators.required],
    Password: ['', Validators.required],
    Address: ['', Validators.required],
    Postcode: ['', Validators.required],
    City: ['', Validators.required],
    Country: ['', Validators.required]
});

createCustomer(currentCustomer: Customer) 
{
    if (!this.AddCustomerForm.valid)
    {
        //some app logic
    }
}
Run Code Online (Sandbox Code Playgroud)

this.AddCustomerForm.valid返回false,但一切看起来都不错.

我试图通过检查控件集合中的status属性来查找.但我想知道是否有办法找到无效的并显示给用户?

reactive angular angular-reactive-forms

59
推荐指数
6
解决办法
4万
查看次数

ngFor(Angular 2)中的动态模板引用变量

如何在元素中声明动态 模板引用变量ngFor

我想使用ng-bootstrap中的popover组件,popover代码(带有Html绑定)如下所示:

<ng-template #popContent>Hello, <b>{{name}}</b>!</ng-template>
    <button type="button" class="btn btn-secondary" [ngbPopover]="popContent" popoverTitle="Fancy content">
    I've got markup and bindings in my popover!
</button>
Run Code Online (Sandbox Code Playgroud)

如何这些元素包装在里面ngFor

<div *ngFor="let member of members">
    <!-- how to declare the '????' -->
    <ng-template #????>Hello, <b>{{member.name}}</b>!</ng-template>
        <button type="button" class="btn btn-secondary" [ngbPopover]="????" popoverTitle="Fancy content">
        I've got markup and bindings in my popover!
    </button>
</div>
Run Code Online (Sandbox Code Playgroud)

嗯......任何想法?

angular-template ng-bootstrap angular

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

Angular2嵌套模板驱动表单

这只是疯狂,看起来没有办法让一个表单中的一个输入在子组件中.

我已阅读所有博客和教程以及所有内容,无法解决这个问题.

问题是当一个子组件要有任何形式的指令(ngModel,ngModelGroup或其他......)时,它不会工作.

这只是模板驱动表单中的一个问题

这是plunker:

import { Component } from '@angular/core';

@Component({
  selector: 'child-form-component',
  template: ` 
  <fieldset ngModelGroup="address">
    <div>
      <label>Street:</label>
      <input type="text" name="street" ngModel>
    </div>
    <div>
      <label>Zip:</label>
      <input type="text" name="zip" ngModel>
    </div>
    <div>
      <label>City:</label>
      <input type="text" name="city" ngModel>
    </div>
  </fieldset>`
})

export class childFormComponent{


}

@Component({
  selector: 'form-component',
  directives:[childFormComponent],
  template: `
    <form #form="ngForm" (ngSubmit)="submit(form.value)">
      <fieldset ngModelGroup="name">
        <div>
          <label>Firstname:</label>
          <input type="text" name="firstname" ngModel>
        </div>
        <div>
          <label>Lastname:</label>
          <input type="text" name="lastname" ngModel>
        </div>
      </fieldset>

      <child-form-component></child-form-component>

      <button type="submit">Submit</button>
    </form>

    <pre>
      {{form.value | …
Run Code Online (Sandbox Code Playgroud)

angular2-forms angular

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

角度2 - ngfor没有包装在容器中

我希望有一个ul元素,然后在我的json中我有html包含来自各种社交媒体网站的列表(li)元素..当我在列表中放置项目时,为每个输出的json记录创建多个ul ..是它可以只输出每个li作为普通的html而不是将它们包装在一个元素中

我的json的小样本

{
    "courses": [{
        "tile_id": 0,
        "tile_content": "<li class=\"grid-item horiz-double blog-tile\" data-item-id=\"0\">yrdy<\/li>"
    }],
}
Run Code Online (Sandbox Code Playgroud)

我的角度服务的小样本 - 这完美地工作并输出json但可能我缺少某种格式设置

public getCourses() {

    this._http.get(this.apiUrl).map(response => response.json()).subscribe(data => {
        // console.log( data.courses );
        this._dataStore.courses = data.courses;

        // console.log(this._coursesObserverXX);

        this._coursesObserverXX.next(this._dataStore.courses);

    }, error => console.log('Could not load courses.'));

}
Run Code Online (Sandbox Code Playgroud)

和我的HTML

<ul class="list-group" *ngFor="#course of courses | async">
      {{ course.tile_content }}
</ul>
Run Code Online (Sandbox Code Playgroud)

目标是没有ngfor输出包装器,也不显示输出为纯HTML而不是纯文本,因为它似乎出来了

angular

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

Angular 2:包含子组件的表单

我有一个组件,它在表单中有一个表单和一些子组件.子组件是使用创建的*ngFor,每个子组件都包含input元素.Angular2编译器给出的错误如[formGroup]未定义.

这个实现是正确的吗?

父组件:

<section class="data-body">
        <form [formGroup]="checkoutForm" novalidate>
            <app-checkout-product-view *ngFor="let item of checkoutData.products" [_product]="item" formGroupName="products"></app-checkout-product-view>
                <div class="col-md-4">
                    <label>Nominee:</label>
                    <select required [(ngModel)]="checkoutData.selectedNominee" [ngModelOptions]="{standalone: true}">
                        <option *ngFor="let nominee of checkoutData.nomineeList" [value]="nominee">{{nominee}}</option>
                    </select>
                </div>
                <div class="col-md-4">
                    <label>Bank Account:</label>
                    <select [(ngModel)]="checkoutData.selectedBank" required [ngModelOptions]="{standalone: true}">
                        <option *ngFor="let bank of checkoutData.bankList" [value]="bank">{{bank}}</option>
                    </select>
                </div>
            </div>
        </form>
    </section>
Run Code Online (Sandbox Code Playgroud)

子组件: app-checkout-product-view

<div class="row">
    <div class="col-md-4">
        <md-input required [(ngModel)]="product.investmentAmount 
                  formControlName="investmentAmount">
            <span md-prefix>&#x20B9;</span><!--Rupee icon-->
        </md-input>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

PS:所有的进口都很好所以我很确定这里没有导入错误

angular2-forms angular

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

Angular - ng-template,其中ngIf内的参数位于ngFor内

我正在尝试构建此模板:

<ul>
    <li *ngFor='let link of links'>
        <ng-container *ngIf="link.type == 'complex'; then complexLink else simpleLink"></ng-container>
    </li>
</ul>

<ng-template #simpleLink>
    ...
    {{ link.some_property }}
</ng-template>

<ng-template #complexLink>
    ...
    {{ link.some_property }}
</ng-template>
Run Code Online (Sandbox Code Playgroud)

问题是在ng-template中未定义链接变量,因此我得到访问未定义的'some_property'的错误.

我很想知道如何将链接变量从ngFor传递到ng-template

很高兴知道这个问题是否有多种解决方案.

angular-template ng-template angular

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

Angular2 Inject ElementRef在单元测试中

我正在尝试测试通过DI接收对ElementRef的引用的组件.

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

@Component({
  selector: 'cp',
  templateUrl: '...',
  styleUrls: ['...']
})
export class MyComponent implements OnInit {

  constructor(private elementRef: ElementRef) {
    //stuffs
  }

  ngAfterViewInit() {
    // things
  }

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

和测试:

import {
  beforeEach,
  beforeEachProviders,
  describe,
  expect,
  it,
  inject,
} from '@angular/core/testing';
import { ComponentFixture, TestComponentBuilder } from '@angular/compiler/testing';
import { Component, Renderer, ElementRef } from '@angular/core';
import { By } from '@angular/platform-browser';

describe('Component: My', () => {
  let builder: TestComponentBuilder;

  beforeEachProviders(() …
Run Code Online (Sandbox Code Playgroud)

unit-testing dependency-injection angularjs-e2e angular

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

对.net核心项目使用<DebugType> Full </ DebugType>和<DebugType> Portable </ DebugType>有什么区别?

要生成打开封面报告,我必须将debugType设置为Full.我在构建服务器上生成报告,因为如果覆盖范围没有达到某个阈值,我必须使构建失败.构建在发布模式下生成.在我的csproj文件中保持debugType Full有什么后果?它会降低生产性能吗?

.net opencover roslyn .net-core

20
推荐指数
2
解决办法
8372
查看次数

在 Angular 13 中实现 Monaco 编辑器

在 Angular 13 中实现 Monaco 编辑器的最佳选项是什么?\n我见过 ngx-monaco-editor,但上次更新是 9 个月后,它\xe2\x80\x99s 升级到 Angular 12,Monaco 版本也有 0.20。 0 (11.02.2020),非常旧:(\n是否有另一种方法可以在 Angular 13 中使用它?

\n

monaco-editor angular

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