小编Dre*_*w13的帖子

Angular2使用ApplicationRef手动实现更改检测

获得更改检测错误

检查后表情发生了变化.上一个值:'true'.当前价值:'假'

所以我想手动运行另一轮变化检测.找到有关使用ApplicationRef.tick()但当前收到错误的信息

ERROR在[默认] C:\ development\SolarUI11\src\app\update\update.component.ts:8:11类型'{selector:string; 风格:任何[]; 模板:任何; 提供者:( typeof ApplicationRef | typeof Date ...'不能分配给'Component'类型的参数.属性'provider'的类型是不兼容的.Type'(typeof ApplicationRef | typeof DatePipe)[]'不能赋值给' Provider []'.类型'typeof ApplicationRef | typeof DatePipe'不能分配给'Provider'类型.类型'typeof ApplicationRef'不能分配给'Provider'类型.类型'typeof ApplicationRef'不能分配给'FactoryProvide r'类型类型'typeof ApplicationRef'中缺少属性'provide'

我想我只是坚持实现这个的语法,自己找不到足够的信息才能使用它.

打字稿:

import { Component, Input, ApplicationRef } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import {NgbDateStruct} from '@ng-bootstrap/ng-bootstrap';
import {DatePipe} from "@angular/common";
import { DataTable } from '../data/datatable';
import { DPS } from '../data/datainfo.ts';

@Component({
  selector: 'update-validation',
  styleUrls: ['../app.component.css'],
  templateUrl: 'update.component.html',
  providers: [DatePipe, ApplicationRef]
}) …
Run Code Online (Sandbox Code Playgroud)

typescript angular2-changedetection angular

8
推荐指数
1
解决办法
4846
查看次数

primeng p-autoComplete 组件上的表单验证不起作用

我有一个包含多个元素的表单。在该表格中,我有两个primeng p-autoComplete组成部分。由于某种原因,我的反应式表单验证未在这些组件上检测到,但在表单的所有其他组件上检测到。

html:

<form [formGroup]="formGroup" (submit)="onSubmit()">
    <div class="ui-g">
  <div class="ui-g-6">
    <label>Generator Name</label>
    <div class="ui-inputgroup">
      <p-autoComplete name="name" formControlName="gen" [suggestions]="hint"
                      (completeMethod)="filter($event)"  field="name"
                      [forceSelection]="true" [dropdown]="true" placeholder="Select"></p-autoComplete>
      <div *ngIf="formErrors['gen']">
        {{formErrors['generator']}}
      </div>
    </div>
  </div>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)

TS:

hint: Gen[];

ngOnInit() {
    this.createForm();
    this.initVariable();
  }

initVariable() {
    this.formErrors = {
      'gen': '',
    };

    this.validationMessages = {
      'gen': {
        'required': 'Gen is required'
      }
    };

  }

createForm() {
    this.formGroup = this.fb.group({
      gen: [null, Validators.required]
    });

    this.formGroup.valueChanges.subscribe(() => this.onValueChanged());
    this.onValueChanged();
  }

onValueChanged() {
    if (this.formGroup === …
Run Code Online (Sandbox Code Playgroud)

primeng angular

6
推荐指数
0
解决办法
2509
查看次数

在Espresso测试中忽略pressBack()

Espresso的方法pressBack()完全被忽略了.我正在模拟器上运行测试.

我正在测试什么?只需调用一个Activity,启动第二个,执行两个后退,并检查我是否已退出应用程序.

testing android android-espresso

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

取消选中所有用* ngFor创建的复选框

我有一个表,该表的列包含使用的每一行的复选框*ngFor。单击按钮后,我要取消选中所有复选框。我尝试使用[(ngModel)]="boxChecked"每个复选框,并在我的按钮单击调用的方法中将该值设置为false,但是每当我仅选中其中一个复选框时,就会导致每个复选框都被选中。单击按钮并不会取消选中所有复选框,但是我仍然需要能够单独选中复选框。

<ng-template pTemplate="body" let-sub let-expanded="expanded" let-columns="columns">
      <tr [pSelectableRow]="subcontract">
        <td *ngFor="let col of columns" [ngSwitch]="true" style="text-align: center">
          <div *ngSwitchCase="col.export" ><input type="checkbox" (change)="checked($event, sub)" [(ngModel)]="boxChecked"></div>
        </td>
      </tr>
</ng-template>
<button type="button"(click)="reset(table)"></button>
Run Code Online (Sandbox Code Playgroud)

ts:

//I send the ID of the table to this method.
reset(table) {
    table.reset();
    this.boxChecked = false;
}
Run Code Online (Sandbox Code Playgroud)

到目前为止,在我的研究中,我还没有看到表上有某种get(index i)(获取索引参数的单行)方法。然后,我可以轻松地遍历表并将每个迭代(行)的复选框设置为false。

angular

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

将页面选择设置为 PrimeNG p 表的最后一页

我需要将我选择的页面p-table作为最后一页。

我能够获取我的表对象:

@ViewChild('myTable') myTable: DataTable;

ngOnInit() {

    this.subService.subsUpdated.subscribe(result => {
      this.fetchSubcontracts();
    });

    this.appForm.subAdded.subscribe(result => {
      this.added = 4;
      this.fetchSubs();
    });

  }
Run Code Online (Sandbox Code Playgroud)

我尝试将我的[first][paginatorPosition]属性绑定p-table到一个属性,但这不起作用。

<p-table #myTable
           [value]="subs"
           sortMode="multiple"
           selectionMode="single"
           (onRowSelect)="onRowSelect($event)"
           (onRowUnselect)="onRowUnselect($event)"
           [(selection)]="selectedSub"
           [columns]="columns"
           dataKey="id"
           [paginator]="subs.length > 0"
           [rows]="5"
           [first]="added"
           >
Run Code Online (Sandbox Code Playgroud)

primeng angular primeng-turbotable

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

使用多个过滤器的Java Stream搜索列表

我有一个Java对象列表(假设getter和setter):

Record(String name, String part, String value);
Run Code Online (Sandbox Code Playgroud)

如果列表包含某个name值和某个值,我需要返回一个布尔part值.

我让它一次为一个过滤器工作:

//assume records are added to this list
List<Record> masterList = new ArrayList<Record>();

boolean check = masterList.stream().map(Record::getName).filter(record.getName()::equals).findFirst().isPresent();
Run Code Online (Sandbox Code Playgroud)

但我得到的错误Non-static method cannot be referenced from a static contextRecord::getPart此尝试:

masterList.stream().map(Record::getName).filter(record.getName()::equals).map(Record::getPart).filter(record.getPart()::equals).findFirst().isPresent();
Run Code Online (Sandbox Code Playgroud)

java java-stream

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

对齐两个垂直的 HTML 表格

我有两张桌子垂直叠在一起。有一个margin-bottom地方将两者分开。

目前代码如下:

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<table class="....">
  <thead>
    <tr>
      <th class="...."></th>
      <th>
        <a href="#list-table" class="....">
          <span class="...">Batch Queue</span>
          <span class="..."></span>
        </a>
      </th>
      <th>
        <a href="#list-table" class="...">
          <span class="...">Start Date</span>
          <span class="..."></span>
        </a>
      </th>
      <th>
        <a href="#list-table" class="...">
          <span class="...">Status</span>
          <span class="..."></span>
        </a>
      </th>
      <th>
        <a href="#list-table" class="...">
          <span class="...">Est Time to Complete</span>
          <span class="..."></span>
        </a>
      </th>
    </tr>
  </thead>
  <tbody>
    <tr ng-repeat="batch in vm.batches | filter : {completion_status:'!'+'100'}">
      <td ng-class="batch.completion_status === '100' ? 'table-status-ok' : (batch.completion_status > '60' ? 'table-status-warning' …
Run Code Online (Sandbox Code Playgroud)

html css angularjs

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

单击按钮时选择所有行

我有一张primeng桌子。当我单击按钮时,我希望选择所有行。

html:

<p-table [columns]="columns" [value]="values"
         selectionMode="multiple" [(selection)]="selectedValues"
         (onRowSelect)=selectRow(selectedValues)
         (onRowUnselect)="unselectRow($event)" #table>
  <ng-template pTemplate="header" let-columns>
    <tr>
      <th *ngFor="let col of columns">
        {{col.header}}
      </th>
    </tr>
  </ng-template>
  <ng-template pTemplate="body" let-val>
    <tr [pSelectableRow]="val">
      <td *ngFor="let col of columns">
        {{val[col.field]}}
      </td>
    </tr>
  </ng-template>
</p-table>

<div class="table-button">
  <p-button (onClick)="selectAll()">Select All</p-button>
  <p-button>Remove</p-button>
</div>
Run Code Online (Sandbox Code Playgroud)

打字稿:

import {Component, OnInit, ViewChild} from '@angular/core';
import {Model} from "../../models/model.model";

@Component({
  selector: 'app-comp',
  templateUrl: './my-component.component.html',
  styleUrls: ['./my-component.component.scss']
})
export class MyComponent implements OnInit {
  @ViewChild('table', {static: false}) table;

  //left out for now
  //values: Model[]; …
Run Code Online (Sandbox Code Playgroud)

angular primeng-datatable

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

从另一个 Typescript 文件访问数组

DPS我的 Typescript 文件之一中有一个数组,该数组未在该文件的类中定义,它只是单独存在。

const DPS: DataTable[] = [
  { tDataPoint: "d1", tICCP: "i1", tStartDate: "s1", tEndDate: "e1" },
  { tDataPoint: "d2", tICCP: "i2", tStartDate: "s2", tEndDate: "e2" },
  { tDataPoint: "d3", tICCP: "i3", tStartDate: "s3", tEndDate: "e3" },
  { tDataPoint: "d4", tICCP: "i4", tStartDate: "s4", tEndDate: "e4" }
];
Run Code Online (Sandbox Code Playgroud)

在不同组件目录中的另一个 Typescript 文件中,我想访问这个数组来操作它。

arrays typescript

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

单击按钮时使用自定义管道的角度过滤器表

我有一个表格,我使用自定义管道成功过滤了它。过滤器基于两个输入,它们共同构成一个表单。我要添加的功能是在单击提交按钮之前不会进行过滤。所以它更像是一个搜索按钮。我发现了大量有关管道的信息,但没有关于在单击按钮时激活它们的信息。

主页.component.html:

<div>
  <label>Start Date:</label>
  <input type="text" [(ngModel)]="startDateValue">
</div>
  <label>End Date:</label>
  <input type="text" [(ngModel)]="endDateValue">
</div>
//'let idx=index' and 'let even=even' are used to change color of the rows but I took out that code. The 'onClick' function just takes the row and uses an EventEmitter to output it.
<tr *ngFor="let dPoint of theData | searchDates:startDateValue:endDateValue; let idx=index; let even=even;" (click)="onClick(dPoint, idx)">
  <td>{{dPoint.tDataPoint}}</td>
  <td>{{dPoint.tICCP}}</td>
  <td>{{dPoint.tStartDate}}</td>
  <td>{{dPoint.tEndDate}}</td>
</tr>
//the button that will execute the filtering
<button type="submit" class="btn icon-search" [disabled]="!secondForm.valid" (click)="submit(secondForm.value)"></button>
Run Code Online (Sandbox Code Playgroud)

mainpage.component.ts: …

html typescript angular2-pipe angular

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