小编HDJ*_*MAI的帖子

PrimeNG Turbotable默认扩展

我有一个具有行扩展功能的PrimeNg可涡轮增压功能.

如何在默认情况下展开行.

这是我的代码:

HTML

<p-table [columns]="cols" [value]="cars" dataKey="vin">
<ng-template pTemplate="header" let-columns>
    <tr>
        <th style="width: 2.25em"></th>
        <th *ngFor="let col of columns">
            {{col.header}}
        </th>
    </tr>
</ng-template>
<ng-template pTemplate="body" let-rowData let-expanded="expanded" let-columns="columns">
    <tr>
        <td>
            <a href="#" [pRowToggler]="rowData">
                <i [ngClass]="expanded ? 'fa fa-fw fa-chevron-circle-down' : 'fa fa-fw fa-chevron-circle-right'"></i>
            </a>
        </td>
        <td *ngFor="let col of columns">
            {{rowData[col.field]}}
        </td>
    </tr>
</ng-template>
<ng-template pTemplate="rowexpansion" let-rowData let-columns="columns">
    <tr>
        <td [attr.colspan]="columns.length + 1">
            <div class="ui-g ui-fluid" style="font-size:16px;padding:20px">
                <div class="ui-g-12 ui-md-3" style="text-align:center">
                    <img [attr.alt]="rowData.brand" src="assets/showcase/images/demo/car/{{rowData.brand}}.png">
                </div>
                <div class="ui-g-12 …
Run Code Online (Sandbox Code Playgroud)

html5 typescript primeng angular primeng-turbotable

18
推荐指数
1
解决办法
8305
查看次数

在Angular 2服务中测试异步(Promise)方法

这是一个有趣的问题:我正在尝试测试使用Ionic BarcodeScanner的服务.我有一个基于离子单元测试库的repo ,以便尝试测试.我正在嘲笑BarcodeScanner.scan方法spyOn(..).and.callFake(..)

问题:当我从组件调用扫描方法时,它可以工作.当我在服务中执行完全相同的操作时,它会抛出超时.

组件测试代码:

it("should be able to set a spy on the scanner and test the component", done => {
    const testBC = "123456";
    const spy = spyOn(TestBed.get(BarcodeScanner), "scan");
    spy.and.callFake(() => {
        return new Promise((resolve, reject) => {
            resolve(testBC);
        })
    });

        component.testScanner().then(res => {
            expect(res).toBe(testBC);
            done();
        }, reason => {
            expect(true).toBe(false);
            done();
        })
});
Run Code Online (Sandbox Code Playgroud)

服务测试代码:

it("should be able to set a spy on the scanner and test the service", done => {
    const testBC = …
Run Code Online (Sandbox Code Playgroud)

angular-services angular2-services ionic3 angular

16
推荐指数
1
解决办法
649
查看次数

保证复制省略的行为是否依赖于用户定义的复制构造函数的存在?

以下代码在GCC 8.0.1下使用或不使用用户定义的复制构造函数的行为有所不同:

#include <cassert>

struct S {
    int i;
    int *p;
    S() : i(0), p(&i) {}
    // S(const S &s) : i(s.i), p(&i) {}  // #1
    // S(const S &s) : i(s.i), p(s.p) {} // #2
    // S(const S &s) = delete;           // #3
};

S make_S() {return S{};}

int main()
{
    S s = make_S();
    assert(s.p == &s.i);
}
Run Code Online (Sandbox Code Playgroud)

使用注释的用户定义的复制构造函数(即使是#2,执行简单的浅复制的那个),断言也不会失败,这意味着保证的复制省略按预期工作.

然而,在没有任何用户定义的复制构造,则断言失败,这意味着该对象smain功能不被缺省构造.为什么会这样?保证复制省略不在这里执行吗?

c++ language-lawyer copy-elision c++17 gcc8

16
推荐指数
1
解决办法
631
查看次数

什么时候使用Ngzone.run()?

我在Angular项目中遇到一个错误,该错误最终通过将代码包装到

this.zone.run(() => {/* my code here */});
Run Code Online (Sandbox Code Playgroud)

答案所述。

我以前的理解zone是angular无法检测到异步callbacks第三方库所做的更改,因为“它们不在angular的范围内zone”。如果我单击a button,则触发的事件不是浏览器的本机click事件,而是click由angular创建的自定义(修补)事件,其handlerzoneso angular中的运行会意识到其回调处理程序所做的更改。

但是我无法理解通过router.navigate()在第三方回调中运行来创建此问题(如此 github问题所示)。是不是Router一个service角本身?为什么zone在第三方中调用时,它不会自动通知angular callback

我通过router.navigate在NGXS的状态缩减器中使用来解决此问题。

我的问题是:

有人可以解释我到底什么时候需要包装我的代码NgZone

调试了几个小时,意识到我的代码没有zone上下文,这很烦人。

angular ngzone

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

Why do I need to call detectChanges / whenStable twice?

First example

I have got the following test:

import { async, ComponentFixture, TestBed } from '@angular/core/testing';

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

@Component({
    template: '<ul><li *ngFor="let state of values | async">{{state}}</li></ul>'
})
export class TestComponent {
    values: Promise<string[]>;
}

describe('TestComponent', () => {
    let component: TestComponent;
    let fixture: ComponentFixture<TestComponent>;
    let element: HTMLElement;

    beforeEach(async(() => {
        TestBed.configureTestingModule({
            declarations: [TestComponent]
        })
            .compileComponents();
    }));

    beforeEach(() => {
        fixture = TestBed.createComponent(TestComponent);
        component = fixture.componentInstance;
        fixture.detectChanges();
        element = (<HTMLElement>fixture.nativeElement);
    });

    it('this test fails', async() => …
Run Code Online (Sandbox Code Playgroud)

testbed angular angular-test

16
推荐指数
2
解决办法
1129
查看次数

合同优先和合同最后意味着什么?

我正在做一些关于Web服务的研究.我没有写任何网络服务,但我正在做一些小的写作.

在我的研究期间,我遇到了合同优先合同最后的条款.

有人可以用可以理解的形式解释这两个吗?

web-services

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

Flex ComboBox,默认值和数据提供者

我有一个Flex ComboBox,由数据提供者填充,一切都很好......

我现在想在0索引处添加默认的" - 选择项目 - "选项,我该怎么做呢仍然使用数据提供者?我没有见过这样的例子,但我无法想象这很难......

apache-flex data-binding combobox

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

导入错误:没有名为 _thread 的模块

在vscode中编译python2报错。但是当我编译python3时它成功了。

print('test')
Run Code Online (Sandbox Code Playgroud)

返回:导入错误:没有名为 _thread 的模块

print('test')
Run Code Online (Sandbox Code Playgroud)

python importerror visual-studio-code

14
推荐指数
1
解决办法
7247
查看次数

Hibernate无法获取当前线程的事务同步会话

我遇到过类似的问题,就像许多人一直有的一样,但我似乎无法弄清楚在我的具体案例中出了什么问题.我正在进行一个简单的数据库调用来测试数据库连接,Hibernate抛出以下异常:

Exception in thread "main" org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread
at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:134)
at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1014)
at boardwalk.computeServer.dao.DbDaoHibernateImpl.getInterpolationJob(DbDaoHibernateImpl.java:73)
at boardwalk.computeServer.ComputeServer.test(ComputeServer.java:39)
at boardwalk.computeServer.ComputeServer.main(ComputeServer.java:32)
Run Code Online (Sandbox Code Playgroud)

以下是相关代码和配置:

pom.xml中:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema  instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-    4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>boardwalk</groupId>
  <artifactId>computeServer</artifactId>
  <version>1.0</version>
  <packaging>jar</packaging>

  <name>marketserver</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>4.1.1.RELEASE</version>
  </dependency>
  <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.33</version>
  </dependency>
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-beans</artifactId>
    <version>4.1.1.RELEASE</version>
  </dependency>
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-aspects</artifactId>
    <version>4.1.1.RELEASE</version>
  </dependency>
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>4.1.1.RELEASE</version>
  </dependency>
  <dependency>
    <groupId>javax.transaction</groupId> …
Run Code Online (Sandbox Code Playgroud)

java spring hibernate transactions

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

如何使ngx-bootstrap模态居中

尝试使用像这样的CSS 中心这个ngx-boostrap模态,但它不起作用:

.modal.fade.in{
  display: flex;
  justify-content: center;
  align-items: center;
}
Run Code Online (Sandbox Code Playgroud)

但是在开发工具中,我可以像这样添加CSS:

.modal.dialog{
  top: 50%
}
Run Code Online (Sandbox Code Playgroud)

所以至少它是垂直居中的,但这是在开发工具中,并且html模板中没有.modal.dialog

有没有办法正确居中ngx-bootstrap模式?

我想通过提供输入消息并添加是/否对话框并输出用户选择(使用EventEmitter)来创建一个通用模态组件以在任何地方使用它

我在以下Plunker中找到了一个示例,但无法在单独的自定义组件中重现它.

plunker示例来自这个网站:https://github.com/valor-software/ngx-bootstrap/issues/2334

更新:

在@Wira Xie回答之后,当我使用静态模态和这个CSS时:

.modal-sm
{
  top: 50%;
  left: 50%;
  width:30em;
  height:18em;
  background-color: rgba(0,0,0,0.5); 
}
Run Code Online (Sandbox Code Playgroud)

模态显示居中,但只有Esc key可以隐藏它,所以当我点击模态外,它仍然可见.

css centering ngx-bootstrap angular ngx-bootstrap-modal

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