我想使用Three.js(@types/three/index)扩展导入到ng6项目中的类型定义,并使用一组将直接附加到相同“名称空间”的函数。类似于:THREE.myFunction()。我不想声明三any来抑制类型检查和linter,并且我想可以包装一个使用JS类/功能扩展三个的香草JS函数,然后再利用typings.d.ts。
首先,我想将THREE.js加载程序导入到我的项目中,这通常定义了一个可扩展的vanilla函数THREE。
我正在尝试将BinaryLoaderng服务导入ng服务,但不确定如何以正确的方式进行操作。
到目前为止,我所做的是:
npm install three --savenpm install @types/three --save-devimport * as THREE from 'three';scripts数组中angular.json
"scripts": [
"./node_modules/three/examples/js/loaders/BinaryLoader.js"
]
Run Code Online (Sandbox Code Playgroud)
到目前为止一切顺利,但是现在我需要创建一个二进制加载器:
import * as THREE from 'three';
// import { BinaryLoader } from 'three';
// import 'three/examples/js/loaders/BinaryLoader';
export class ThreeManagerService {
const loader = new THREE.BinaryLoader();
...
Run Code Online (Sandbox Code Playgroud)
而且我必须找到BinaryLoader以@types/three/index某种方式添加的方法。这样,我应该能够扩展类型定义,以便能够创建新类型THREE.BinaryLoader。可以做这样的事情吗?
我得到的警告是:
警告:./src/app/shared/three-manager.service.ts 24:25-43“在'三个'中找不到导出'BinaryLoader'(导入为'三个') …
我正在使用Angular 5.x模板,但是我使用https://update.angular.io/指南将其升级到Angular 6 。现在我的构造函数中有这个错误
Typescript Error: TS2314: Generic type 'ElementRef<T, any>' requires 2 type argument(s)
Run Code Online (Sandbox Code Playgroud)
我的代码:
import { Component, Input, Output, EventEmitter, ElementRef, HostListener } from '@angular/core';
@Component({
selector: 'sidebar',
templateUrl: './sidebar.component.html'
})
export class SidebarComponent {
@HostListener('document:click', ['$event'])
clickout(event) {
if(!this.eRef.nativeElement.contains(event.target)) {
this.hideMobileSidebar.emit(true);
}
}
constructor(private eRef: ElementRef) {
}
...
Run Code Online (Sandbox Code Playgroud)
我在以前的Angular版本5中没有此错误。
有什么变化?我不理解文档:( https://angular.io/api/core/ElementRef
我正在尝试在菜单列表中实现有角度的材质标志。
是否可以将徽标放置在列表项的中央?
官方文件说:“默认情况下,徽章将放置在之后的上方。可以通过定义属性matBadgePosition跟随其后的| below和after | after来更改方向。”
但是我需要排除此|在以下位置选项
或至少可以将整个徽章设置为可见
我在Angular中有一个结构如下的模块:
moduleName
componentA
componentB
Run Code Online (Sandbox Code Playgroud)
现在componentA和componentB它们非常相似,因为它们共享一些属性和方法,例如:
protected available: boolean = true;
Run Code Online (Sandbox Code Playgroud)
因为不想重复自己,所以我创建了一个基类,用于存储所有这些内容:
export abstract class BaseComponent {
protected available: boolean = true;
}
Run Code Online (Sandbox Code Playgroud)
并且两个控制器都从该类继承:
import { BaseComponent } from '../base.component';
export class ComponentA extends BaseComponent implements OnInit {
constructor() {
super();
}
ngOnInit() {
console.log(this.available);
}
}
Run Code Online (Sandbox Code Playgroud)
这样很好。但是,当我研究这种灵魂时,很多人都在说:
不要使用继承,在这种情况下请使用合成。
好的,但是我该如何使用合成呢?与当前解决方案相比,收益真的那么大吗?
非常感谢您的宝贵时间。
从Angular 5迁移到6之后,我遇到了静态注入器的问题.错误是:
错误错误:StaticInjectorError(AppModule)[StorageService - > LocalStorageService]:StaticInjectorError(Platform:core)[StorageService - > LocalStorageService]:NullInjectorError:没有LocalStorageService的提供者!atInullInjector.push ../ node_modules/@angular/core/fesm5/core.js.NullInjector.get(core.js:1062)at resolveToken(core.js:1300)at tryResolveToken(core.js:1244)at StaticInjector在StaticInjector.push的tryResolveToken(core.js:1244)的resolveToken(core.js:1300)处的.push ../ node_modules/@angular/core/fesm5/core.js.StaticInjector.get(core.js:1141)位于_createClass(core.js:8423)的resolveNgModuleDep(core.js:8376)位于_createProviderInstance(core.js)的../node_modules/@angular/core/fesm5/core.js.StaticInjector.get(core.js:1141) :8393)在_createClass(core.js:8423)处的resolveNgModuleDep(core.js:8356)atAndModuleRef.的breakNgModuleDep(core.js:8356)处的createProviderInstance(core.js:8393) .push ../ node_modules/@ angular atcore /fesm5/core.js.NgModuleRef_.get(core.js:9064)at resolveDep(core.js:9429)at createClass(core.js:9309)at createDirectiveInstance(core.js:9186)at createViewNodes(core .js:10406)在object.de上的callWithDebugContext(core.js:11351)的createRootView(core.js:10320)在ComponentFactoryBoundToModule.push ../ node_modules的ComponentFactory_.push ../ node_modules/@angular/core/fesm5/core.js.ComponentFactory_.create(core.js:8666)的bugCreateRootView [as createRootView](core.js:10838) /@angular/core/fesm5/core.js.ComponentFactoryBoundToModule.create(core.js:3315)at ApplicationRef.push ../ node_modules/@angular/core/fesm5/core.js.ApplicationRef.bootstrap(core.js: 4550)at core.js:4358 at ArrayRef.push ../ node_modules/@angular/core/fesm5/core.js.PlatformRef._moduleDoBootstrap(core.js:4358)at core.js:4324位于ZoneDelegate.push ../ node_modules/zone的Object.onInvoke(core.js:3824)上的ZoneDelegate.push ../ node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke(zone.js:388)区域中的.js/dist/zone.js.ZoneDelegate.invoke(zone.js:387)位于Zone.push ../ node_modules/zone.js/dist/zone.js.Zone.run(zone.js:138) .js:872 at ZoneDelegate.push ../ node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask(zone.js:421)at Object.onInvokeTask(core.js:3815)a 在Zone.push ../ node_modules/zone.js/dist/zone.js.Zone中的ZoneDelegate.push ../ node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask(zone.js:420). runTask(zone.js:188)
import { InfiniteScrollModule } from 'ngx-infinite-scroll';
import { AuthModule } from './auth/auth.module';
import { ConfigurationModule } …Run Code Online (Sandbox Code Playgroud)我遇到涉及参数的路由问题。当我尝试使用浏览器的后退按钮返回时,前一个组件的ngoninit不会触发。
重现Angular教程中的错误的步骤:
npm installng build --prod --build-optimizer或ng build --prod通过执行这些步骤,您将看到仪表板上未加载顶级英雄,这与我的应用程序存在的问题完全相同。这是因为专门使用“后退”按钮返回时未调用ngOnInit。
注意事项:
此问题仅在使用Firefox,Chrome或Opera时发生。
使用开发模式时不会出现此问题ng serve。
我更新到角度7,仍然有相同的问题。
有什么办法可以解决这个问题?在angular的repo问题中,我什么都没找到。
我有这个JPA查询,我想从Spring生成Angular Barchart:
public List<PaymentTransactionsDailyFacts> findPaymentTransactionsDailyFacts(LocalDateTime start_date, LocalDateTime end_date) {
String hql = "SELECT SUM(amount) AS sum_volume, COUNT(*) AS sum_Transactions " +
" WHERE (created_at BETWEEN :start_date AND :end_date )" +
" GROUP BY DATE(created_at)";
TypedQuery<PaymentTransactionsDailyFacts> query = entityManager.createQuery(hql,
PaymentTransactionsDailyFacts.class).setParameter("start_date", start_date).setParameter("end_date", end_date);
List<PaymentTransactionsDailyFacts> data = query.getResultList();
return data;
}
Run Code Online (Sandbox Code Playgroud)
预期的查询结果:
Date | Amount| Number of transactions per day |
11-11-2018 | 30 | 3 |
11-12-2018 | 230 | 13 |
Run Code Online (Sandbox Code Playgroud)
JPA查询中的映射对象:
public class DashboardDTO {
private Date date;
private int …Run Code Online (Sandbox Code Playgroud) 我有一个数组作为集合,我想将其加载到下拉列表中,并希望在某种情况下进行默认选择,但我不知道该如何实现。
app.component.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-commingsoon',
templateUrl: './commingsoon.component.html',
styleUrls: ['./commingsoon.component.css']
})
export class CommingsoonComponent implements OnInit {
public collection = [];
constructor() {
for(let i = 1; i<=10 ; i++) {
this.collection.push(`Angular: ${i}`);
}
}
ngOnInit() {
}
}
Run Code Online (Sandbox Code Playgroud)
app.component.html
<select name="" id="" style="position:relative; left: 100px">
<option *ngFor="let i of collection;" value="{{i}}" [selected]="i == Angular: 2">{{ i }}</option>
</select>
Run Code Online (Sandbox Code Playgroud)
我希望下拉列表应为i == Angular:2时的选定值
我有一个会话在 20 分钟不活动后过期的应用程序。这个应用程序的用户很懒惰,所以我想他们会在早上喝完咖啡后继续使用这个应用程序,并且对与 Web API 通信会抛出的错误感到惊讶。我的想法是拦截重定向到登录页面,服务器可能会在会话到期后下次访问 Web API 时引发。
所以我写了一个拦截器:
@Injectable()
export class SessionEndInterceptor implements HttpInterceptor {
constructor() {}
intercept(
req: HttpRequest<any>,
next: HttpHandler
): Observable<HttpEvent<any>> {
{
const initialUrl = req.url;
return next.handle(req).pipe(
map((event: HttpEvent<any>) => {
const res = (event instanceof HttpResponse) && event as HttpResponse<any>;
if (res && this.checkIfSessionEnd(initialUrl, res.url)) {
window.location.href = this.replaceRedirectionWithCurrentLocation(
res.url
);
} else {
return event;
}
})
);
}
}
private checkIfSessionEnd(initialUrl: string, currentUrl: string): boolean {
const isInitialUrlLogin = this.isLoginUrl(initialUrl); …Run Code Online (Sandbox Code Playgroud) 在客户端(使用Angular 6),我需要使用HttpClient向服务器端发送Post请求。示例源代码如下
let request = {'username': 'username', 'password': 'password'}
this.httpClient.post("http://10.116.43.18:8002/user/login", request, { headers: new HttpHeaders().set('Access-Control-Allow-Origin','*'), observe: 'response' }).subscribe(
data => {
console.log("Success");
console.log(data);
},
error => {
console.log("Error");
console.log(error);
}
)
Run Code Online (Sandbox Code Playgroud)
该示例代码在Chrome,IE中可以正常运行,但是在Edge中则无法运行。我在Edge的Developer模式下检查了Network选项卡,似乎只发送了GET请求(不是我期望的POST请求,这很奇怪)。我在Edge中收到以下消息:
[对象对象]:{错误:对象,标头:对象,消息:“(未知URL)的HTTP错误响应:0未知错误”,名称:“ HttpErrorResponse”,确定:false ...}
错误:对象气泡:错误可取消:错误cancelBubble:错误currentTarget:null defaultPrevented:错误eventPhase:2 isTrusted:true length可计算:false加载:0 returnValue:true
srcElement:对象msCaching:“自动” onabort:null onerror:null onload:null onloadend:null onloadstart:null onprogress:null onreadystatechange:null ontimeout:null readyState:4响应:“” responseText:“” responseType:“文本” responseURL: “” 0:
目标:对象msCaching:“自动” onabort:空onerror:空onload:空onloadend:空onloadstart:空onprogress:空onreadystatechange:空ontimeout:空readyState:4响应:“” responseText:“” responseType:“文本” responseURL: “” 0:时间戳:30184.21007896917总计:0类型:“错误”
原型:对象
标头:对象
标头:对象大小:0
proto:对象lazyUpdate:null
normalizedNames:对象
proto:对象消息:“针对(未知URL)的HTTP故障响应:0未知错误”名称:“ HttpErrorResponse”确定:错误状态:0 statusText:“未知错误” URL:null
原型:对象
您是否有解决此问题的想法?
angular ×10
angular6 ×10
typescript ×5
angular-cli ×1
angular5 ×1
composition ×1
java ×1
javascript ×1
three.js ×1