上下文 - 我正在尝试创建一个可以包含许多组件的自定义下拉列表.我可以通过<ng-content>标签完成这个,但我的团队固执地坚持他们不喜欢这样.他们希望能够几乎完全通过打字稿代码来实例化这个下拉列表.
我想我可以通过DynamicComponentLoader实现这一点,但不幸的是,我发现的所有好教程都使用了loadIntoLocation()函数,现在它已经消失了.所以我尝试使用loadAsRoot()函数,但它不起作用.
这是我正在尝试做的事情:
Main.ts:
import { Component } from '@angular/core';
import { MyDropdown } from './MyDropdown';
@Component({
selector: 'my-app',
template: `
<my-dropdown [contentModels]="dropdownContentModels"></my-dropdown>
`
})
export class Main {
dropdownContentModels: any[];
constructor() {
var someComponentModel = {selector: 'some-component', text: 'some'};
var otherComponentModel = {selector: 'other-component', text: 'other'};
this.dropdownContentModels = [someComponentModel, otherComponentModel];
}
}
Run Code Online (Sandbox Code Playgroud)
MyDropdown.ts:
import { Component } from '@angular/core';
import { InjectComponent } from './InjectComponent';
@Component({
selector: 'my-dropdown',
inputs: ['contentModels'],
directives: [InjectComponent],
template: `
<div …Run Code Online (Sandbox Code Playgroud) 更新:根据 Thierry Templier 的回应:
下面基本上是我想要做的,但不幸的是内部组件没有渲染。有没有办法像这样通过 HTML 选择器嵌套组件?
<custom-menu-bar-component (onCustomEvent)="handleEvent($event)">
<custom-button-component></custom-button-component>
<custom-dropdown-component></custom-dropdown-component>
</custom-menu-bar-component>
Run Code Online (Sandbox Code Playgroud)
在我的 chrome 调试器中,我只看到正在渲染的外部组件:
<custom-menu-bar-component>
<div class="row">
** Nothing here, where my two inner components should be :(
</div>
</custom-menu-bar-component>
Run Code Online (Sandbox Code Playgroud)
我的组件如下所示:
CustomMenuBarComponent.ts:
import {Component} from 'angular2/core'
import {CustomButtonComponent} from './CustomButtonComponent'
import {CustomDropdownComponent} from './CustomDropdownComponent'
@Component({
selector: 'custom-menu-bar-component',
directives: [CustomButtonComponent, CustomDropdownComponent],
template: `
<div class="row"></div>
`
})
export class CustomMenuBarComponent {
}
Run Code Online (Sandbox Code Playgroud)
自定义按钮组件.ts:
import {Component, EventEmitter} from 'angular2/core'
import {CustomEvent} from './CustomEvent'
@Component({
selector: 'custom-button-component',
outputs: ['onCustomEvent'],
template: `
<button …Run Code Online (Sandbox Code Playgroud) 我无法建立全新的项目。我使用https://start.spring.io/生成了一个全新的Spring 2.0 MongoDB Maven项目,并且我希望为我的集成测试提供一个嵌入式MongoDB数据库。Spring初始化器为此添加了对de.flapdoodle.embed.mongo的依赖。
但是每次我尝试运行“ mvn clean package”时,在测试过程中都会出现以下错误:
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'embeddedMongoServer' defined in class path resource
[org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.class]:
Invocation of init method failed; nested exception is java.io.IOException:
Could not start process: <EOF>
at de.flapdoodle.embed.mongo.AbstractMongoProcess.onAfterProcessStart(AbstractMongoProcess.java:79) ~[de.flapdoodle.embed.mongo-2.0.3.jar:na]
at de.flapdoodle.embed.process.runtime.AbstractProcess.<init>(AbstractProcess.java:116) ~[de.flapdoodle.embed.process-2.0.2.jar:na]
at de.flapdoodle.embed.mongo.AbstractMongoProcess.<init>(AbstractMongoProcess.java:53) ~[de.flapdoodle.embed.mongo-2.0.3.jar:na]
at de.flapdoodle.embed.mongo.MongodProcess.<init>(MongodProcess.java:50) ~[de.flapdoodle.embed.mongo-2.0.3.jar:na]
at de.flapdoodle.embed.mongo.MongodExecutable.start(MongodExecutable.java:44) ~[de.flapdoodle.embed.mongo-2.0.3.jar:na]
at de.flapdoodle.embed.mongo.MongodExecutable.start(MongodExecutable.java:34) ~[de.flapdoodle.embed.mongo-2.0.3.jar:na]
at de.flapdoodle.embed.process.runtime.Executable.start(Executable.java:108) ~[de.flapdoodle.embed.process-2.0.2.jar:na]
Run Code Online (Sandbox Code Playgroud)
我想念什么?
我的应用程序文件非常简单:
@SpringBootApplication
public class NewnewinternetApplication {
public static void main(String[] args) {
SpringApplication.run(NewnewinternetApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
我的配置文件非常简单:
@Configuration
@EnableMongoRepositories …Run Code Online (Sandbox Code Playgroud) 我的自定义表格组件有一个全选指令。我希望我的指令的用户能够通过两种方式实例化它:
1:
<my-custom-table>
<input type="checkbox" my-select-all-directive/>
</my-custom-table>
Run Code Online (Sandbox Code Playgroud)
2:
<input type="checkbox" [table]="myTableRef" my-select-all-directive/>
<my-custom-table #myTableRef></my-custom-table>
Run Code Online (Sandbox Code Playgroud)
我能够通过在指令的构造函数中使用 Host、Inject 和forwardRef 获得第一种工作方式:
constructor(@Host() @Inject(forwardRef(() => MyCustomTableComponent)) table?: MyCustomTableComponent) {
this.table = table; //later I can call this.table.selectAll();
}
Run Code Online (Sandbox Code Playgroud)
但是当我以第二种方式实例化它时,我收到一个异常,抱怨没有 MyCustomTableComponent 的提供程序,大概是因为 MyCustomTableComponent 不是第二种实例化方式中的父级,因此 Host 和forwardRef 不返回任何内容...
我怎样才能使该参数可选?因此,我的指令使用其父级或祖级 MyCustomTableComponent(如果存在),或者使用传递给它的任何表作为输入...
我正在尝试设置将运行机器人测试的gradle任务。Robot使用python库与Selenium进行交互,以便通过浏览器测试网页。但是不幸的是,似乎安装https://github.com/robotframework/Selenium2Library的唯一方法是通过pip- pip install robotframework-selenium2library。有没有办法让Gradle在我的任务中运行此命令?
这是我所拥有的:
build.gradle:
configurations {
//...
acceptanceTestRuntime {extendsFrom testCompile, runtime}
}
dependencies {
//...
acceptanceTestRuntime group: 'org.robotframework', name: 'robotframework', version: '2.8.7'
//The following doesn't work, apparently this library isn't on maven...
//acceptanceTestRuntime group: 'org.robotframework', name: 'Selenium2Library', version: '1.+'
}
sourceSets {
//...
acceptanceTest {
runtimeClasspath = sourceSets.test.output + configurations.acceptanceTestRuntime
}
}
task acceptanceTest(type: JavaExec) {
classpath = sourceSets.acceptanceTest.runtimeClasspath
main = 'org.robotframework.RobotFramework'
args '--variable', 'BROWSER:gc'
args '--outputdir', 'target'
args 'src/testAcceptance'
}
Run Code Online (Sandbox Code Playgroud)
我的机器人资源文件-login.resource.robot:
*** Settings *** …Run Code Online (Sandbox Code Playgroud) 我很震惊,这个答案并不容易找到,但是 - 如何将我的 Spring-Boot 应用程序的 JPA 实体配置为全部自动修剪每个字符串属性?
我正在使用旧式 DB2 数据库,其中每个 CHAR 列的每个值都由我无法控制的各种应用程序填充尾随空格。大约有 50 个带有许多 CHAR(N) 列的互连表,我必须对数据进行无数次转换和比较,而这些转换/比较永远不会与尾随空格一起使用。所以我发现自己在我的代码中调用了大约 10 亿次 trim() 。
覆盖实体 POJO 类的 getter/setter 方法感觉很恶心,因为有数百种方法,而且我刚刚通过使用 Lombok 将它们全部删除。Pleeeeaaase 告诉我有一种方法可以配置 Spring/Hibernate 以自动修剪每个 CHAR(N) String 列的尾随空格...
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import javax.persistence.*;
@Data
@NoArgsConstructor
@Entity
@Table(name="MEASUREMENT_TYPE")
public class MeasurementType {
@Id
@Column(name="MSR_TYP_CD")
private short measurementTypeCode;
@Column(name="DES_TXT", columnDefinition = "CHAR", length = 5)
private String description;
}
Run Code Online (Sandbox Code Playgroud) 我正在从导入的库中扩展一个非常简单的Java接口.界面非常简单,它声明的唯一方法是属性列表的getter和setter.
我的应用程序是用Groovy编写的,所以我想用Groovy类实现这个Java接口.
我的印象是Groovy默认为其任何类的属性创建了getter和setter - 我可以使用这些默认的getter和setter来满足Java接口的要求吗?
Library的Java接口:
public interface Animal { // java interface
public String getName();
public void setName(String name);
public Integer getAge();
public void setAge(Integer age);
}
Run Code Online (Sandbox Code Playgroud)
我希望我能用Groovy这样实现它(但我的编译器抱怨缺少setter):
public class Cat implements Animal { // Groovy class
public String name;
public Integer age;
}
Run Code Online (Sandbox Code Playgroud) 当我尝试将常规按钮和ImageButton设置为相同时,我在LinearLayout中得到了一些奇怪的行为layout_weight.图像按钮的android:src资源非常小,非常适合ImageButton,没有任何问题.即使它们的宽度应该相同,但由于某种原因,ImageButton的宽度大约是普通按钮其余部分的2/3.如果我将ImageButton的乘以layout_weight10,它更接近正确的大小,但为什么这不起作用?
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1">
<Button
android:id="@+id/clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/clear"/>
<Button
android:id="@+id/left_paren"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/left_paren"/>
<Button
android:id="@+id/right_paren"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/right_paren"/>
<ImageButton
android:id="@+id/backspace"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:adjustViewBounds="true"
android:contentDescription="@string/backspace"
android:src="@drawable/backspace"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) android android-layout android-imagebutton android-layout-weight
我有一个注入服务,HttpRequestService,当没有服务器时我想用MockHttpRequestService替换,因为我在开发模式下运行(npm start).这个MockHttpRequestService将发回非常简单的响应.
我以为我找到了一种动态替换我的HttpRequestService的方法,但不幸的是我发现HttpRequestService仍在使用中.这是我试过的:
main.ts
import {bootstrap} from '@angular/platform-browser-dynamic';
import {provide} from '@angular/core';
import {ROUTER_PROVIDERS, Router} from '@angular/router-deprecated';
import {HashLocationStrategy, LocationStrategy} from '@angular/common'
import {Http, HTTP_PROVIDERS} from '@angular/http';
import {CORE_DIRECTIVES} from '@angular/common';
import {HttpRequestService} from './app/services/HttpRequestService';
import {MockHttpRequestService} from './app/services/MockHttpRequestService'
import {MyConfigInjectable} from './app/MyConfigInjectable';
import {SomeService} from './app/services/SomeService';
export function main(initialState?: any): Promise<any> {
let providers = [
...HTTP_PROVIDERS,
...CORE_DIRECTIVES,
...ROUTER_PROVIDERS,
provide(LocationStrategy, { useClass: HashLocationStrategy })
];
if(process.env.ENV === 'development'){
console.log('Is it set to development?'); //Yes. Yes it is.
providers.push(MyConfigInjectable);
providers.push(SomeService); …Run Code Online (Sandbox Code Playgroud)