我正在尝试加载pictureA或pictureB.我的第一个解决方案是这样的:
<img *ngIf="my_picture" src="{{my_picture}}" width="180" height="80" >
<img *ngIf="default_picture && !my_picture" src="{{default_picture}}">
Run Code Online (Sandbox Code Playgroud)
但我想使用if- else就像API参考:
<div *ngIf="condition; else elseBlock">...</div>
<ng-template #elseBlock>...</ng-template>
Run Code Online (Sandbox Code Playgroud)
所以,我试着这样做:
<div *ngIf="my_picture; else elseBlock">
<img src="{{my_picture}}" >
</div>
<ng-template #elseBlock>
<img src="{{default_picture}}" >
</ng-template>
Run Code Online (Sandbox Code Playgroud)
但是我得到了一个很大的异常堆栈跟踪:
Run Code Online (Sandbox Code Playgroud)zone.js:388 Unhandled Promise rejection: Template parse errors: Can't bind to 'ngIfElse' since it isn't a known property of 'div'. (" --> <div [ERROR ->]*ngIf="my_picture; else elseBlock"> <img src="{{my_picture}}"): UserComponent@15:13 Property binding ngIfElse not used by any directive …
我习惯用plattform-browser-dynamic 2.0.0导入bootstrap,如下所示:
import { bootstrap } from '@angular/platform-browser-dynamic/';
Run Code Online (Sandbox Code Playgroud)
现在我创建新的Projekt并使用角度版本2.2.0 Plattform-browser-dynamic packages具有版本2.2.0:
"@angular/common": "~2.2.0",
"@angular/compiler": "~2.2.0",
"@angular/core": "~2.2.0",
"@angular/forms": "~2.2.0",
"@angular/http": "~2.2.0",
"@angular/platform-browser": "~2.2.0",
"@angular/platform-browser-dynamic": "~2.2.0",
"@angular/router": "~3.2.0",
"@angular/upgrade": "~2.2.0",
"angular-in-memory-web-api": "~0.1.15"
Run Code Online (Sandbox Code Playgroud)
我尝试使用包2.0.0导入bootstrap,但是找不到它.我的代码:
import { bootstrap } from '@angular/platform-browser-dynamic/*';
import {AppComponent} from "./app.component";
bootstrap(AppComponent);
Run Code Online (Sandbox Code Playgroud)
错误:
错误TS2305:模块'"../ node_modules/@angular/platform-browser-dynamic/index"'没有导出成员'bootstrap'.
我该如何解决这个问题?我找不到类似的lib.
我正面临着有趣的 LazyInitializationException 解决方案。为了防止这种情况(在 OneToMany 或 ManyToMany 上),一种已知的解决方案是使用 JOIN FETCH Query。你可以看到她的几个例子之一:https ://thoughts-on-java.org/best-practices-for-many-to-many-associations-with-hibernate-and-jpa/
其他更简单的解决方案是使用 Spring 中的 @Transactional。例如像这样:
@DeleteMapping(value ="/product/{tagId}")
@ResponseBody
@Transactional
public String deleteProductWithoutRelation(@PathVariable String product, Model model) {
Optional<Product> pr = productService.selectProduct(product);
if (pr.isPresent()) {
tag.get().getCustomer().size(); //usualy throws LazyInitializationException,
//without JOIN-FETCH Statment or @Transactional
return deletedTagId;
}
Run Code Online (Sandbox Code Playgroud)
当然,您可以在存储库服务中放置一些方法的@Transactional,以封装此解决方案。那么这两种解决方案的优点或缺点是什么?