我面临的问题是在两个状态之间传递数据而不暴露网址中的数据,就像用户不能真正直接落在这种状态上一样.
例如.我有两个状态"A"和"B".我正在状态"A"中进行一些服务器调用,并将调用的响应传递给状态"B".服务器调用的响应是一个字符串消息,这很长,所以我不能在url中公开它.
那么在角度ui路由器中有没有办法在状态之间传递数据,而不使用url params?
我无法解决这个问题。当应用程序加载时,本机会抛出警告。
WARN `new NativeEventEmitter()` was called with a non-null argument without the required `addListener` method.
WARN `new NativeEventEmitter()` was called with a non-null argument without the required `removeListeners` method.
Run Code Online (Sandbox Code Playgroud) 在 Cypress 中,我想根据其文本内容从一组按钮中选择一个按钮。我该怎么做?这是我的方法:
export const getCustomerButton = () => getNavigationSidenav()
.find('mat-expansion-panel-header')
.each(($el, index, $list) => {
const text = $el.find('.mat-content > mat-panel-title').text();
if (text === 'Customer') {
return $el;
}
return null;
});
Run Code Online (Sandbox Code Playgroud)
我现在的问题是我必须从元素数组中过滤掉空值。有没有更简单的方法?
Angular文档说:
响应正文不会返回您可能需要的所有数据.有时,服务器返回特殊标题或状态代码以指示某些条件,并且检查这些条件是必要的.要做到这一点,你可以告诉HttpClient你想要完整的响应,而不仅仅是带有observe选项的body:
http
.get<MyJsonData>('/data.json', {observe: 'response'})
.subscribe(resp => {
// Here, resp is of type HttpResponse<MyJsonData>.
// You can inspect its headers:
console.log(resp.headers.get('X-Custom-Header'));
// And access the body directly, which is typed as MyJsonData as requested.
console.log(resp.body.someField);
});
Run Code Online (Sandbox Code Playgroud)
但是当我尝试这个时,我得到一个编译时错误(尽管没有运行时错误,按预期工作):
错误TS2345:类型'{headers:HttpHeaders; 观察:字符串; ''不能赋值给'{headers?:HttpHeaders |'类型的参数 {[header:string]:string | 串[]; }; 观察?:"身体"; params?:Ht ......'.财产'观察'的类型是不相容的.类型'string'不能分配给''body''.
为什么?我用"@angular/http": "^5.1.0"
这是我的代码版本:
login(credentials: Credentials): Observable<any> {
const options = {
headers: new HttpHeaders({'Content-Type': 'application/json'}),
observe: 'response'
};
return this.httpClient.post<any>(`${environment.USER_SERVICE_BASE_URL}`,
{'username': credentials.username, 'password': credentials.password}, options)
.map((res) => ...
Run Code Online (Sandbox Code Playgroud) 您如何以编程方式与 Cypress 的 Angular/NGRX 交互?cypress 文档似乎仅指 React:https : //www.cypress.io/blog/2018/11/14/testing-redux-store/
// expose store when run in Cypress
if (window.Cypress) {
window.store = store
}
cy
.window()
.its('store')
.invoke('dispatch', { type: 'ADD_TODO', text: 'Test dispatch' })
// check if the app has updated its UI
Run Code Online (Sandbox Code Playgroud)
这将是 React 方法;那么 Angular 呢?
最近推出了NGRX/Entities:
https://medium.com/ngrx/introducing-ngrx-entity-598176456e15 https://github.com/ngrx/platform/tree/master/example-app
并且因为它们是以适配器处理(读取:单个)映射数据结构的方式制作的,并且在初始化时获得剩余的reducer状态,我想知道......
是否可以在一个减速器/适配器中容纳多个实体?接口说没有,但可能有黑客或计划未来?如果我在一个reducer中已经有多个地图怎么办?我是否被迫将其拆分或避开实体功能?
以下答案是有效的.(在这个例子中,延迟加载但不一定是)模块的另一种方法是将reducers与ActionReducerMap结合使用:
在你的lazy.module.ts中:
export interface LazyState {
lazyAState: LazyAState;
lazyBState: LazyBState;
}
export const lazyReducers: ActionReducerMap<LazyState> = {
lazyA: lazyAReducer,
lazyB: lazyBReducer
};
export interface AppState extends forRoot.AppState {
lazy: LazyState;
}
@NgModule({
imports: [
LazyRoutingModule,
StoreModule.forFeature('lazy', lazyReducers),
EffectsModule.forFeature([LazyEffects])
]
})
export class LazyModule {
static forRoot() {
return {
ngModule: LazyModule,
providers: [],
};
}
}
Run Code Online (Sandbox Code Playgroud)
在lazy.selectors.ts中(从reducer文件导入适配器):
export const getLazyState = createFeatureSelector<LazyState>('lazy');
const getLazyAState = createSelector(getLazyState, (state: LazyState) => state.lazyAState);
const getLazyBState = createSelector(getLazyState, (state: …Run Code Online (Sandbox Code Playgroud) 如何使用Spring后端和Angular2前端创建Maven多模块项目?分别使用spring initializr(https://start.spring.io)和angular cli似乎很简单,但是如何将其组织为具有链接但独立的pom文件的多模块Maven项目?我应该创建和初始化那些值和顺序?我可以使用Intellij IDEA,如果它让事情变得更容易,但我对CMD也很好(我在Windows上).
我在这里找到的唯一教程是:https://blog.jdriven.com/2016/12/angular2-spring-boot-getting-started/但该人使用了一些自编的"frontend-maven-plugin"我不想.有人可以解释这些步骤或将我链接到一个不使用第三方资源但只是清理Spring和Angular2的教程吗?
编辑:当我发布这个问题时,WebDevelopment对我来说是最新的.下面的解决方案在开始时工作,但为了更好的可扩展性,我们决定稍后进行单独的项目:一个FE项目包含多个Angular应用程序和许多FE-libs(请查看NRWL的NX).每个BE-Microservice都有一个项目,每个项目都可以在CI-Pipelines中单独部署.谷歌自己采用所有FE和BE的一个项目的方法,但他们确实有特殊要求(所有的库必须在最新版本中相互合作)并且他们使用ABC堆栈(Angular + Bazel + Closure)堆栈,但尚未完全公开,但值得关注:https://github.com/angular/angular/issues/19058
Google地图提供了几个月的功能,可以下载某个地理区域供以后离线使用.我在我的应用程序中使用谷歌地图Android API,我发现在离线时,与真正的谷歌地图应用程序相比,我无法完全放大我的应用程序中的街道级别,因此可能不会使用下载的数据.
有没有办法让我的应用程序使用它?
比方说,我有一个对象Person,其字段类型为FirstName和LastName.现在我也有一个List<Person>,我喜欢使用流.
现在我想生成一个Map<FirstName, List<LastName>>以便将具有相同名字的人分组.如何在不编写大量代码的情况下解决这个问题?到目前为止我的方法是
personList
.stream()
.collect(Collectors.groupingBy(
Person::getFirstName,
person -> person.getLastName() // this seems to be wrong
));
Run Code Online (Sandbox Code Playgroud)
但似乎这是分配地图价值的错误方法.我应该改变什么?或者我应该使用.reduce new HashMap<FirstName, List<LastName>>()作为初始值,然后通过将元素放入其中来聚合它?
我不理解高级REST CLient(取代传输客户端)和Spring Data Elasticsearch之间的关系.
有一些教程(https://www.baeldung.com/spring-data-elasticsearch-tutorial)显示了如何使用自动实现的方法(如getSomethingById())进行JPA样式的查询.他们利用这个界面:
public interface ElasticsearchRepository<T, ID extends Serializable> extends ElasticsearchCrudRepository<T, ID> {
Run Code Online (Sandbox Code Playgroud)
但ElasticsearchRepository似乎需要一个@Configuration带有ElasticsearchTemplate-Bean的-Class并且需要TransportClient.据我所知,没有办法用高/低级别的Java Rest客户端替换它,不是吗?
所以如果我想使用最新的官方客户端,对我来说没有JPA的好处?
java spring elasticsearch spring-data spring-data-elasticsearch
angular ×4
cypress ×2
java ×2
ngrx ×2
spring ×2
android ×1
angular-cli ×1
angularjs ×1
collectors ×1
end-to-end ×1
google-maps ×1
java-stream ×1
javascript ×1
maven ×1
parameters ×1
react-native ×1
reactjs ×1
spring-boot ×1
spring-data ×1
state ×1