我有一个BaseComponent需要注入Service_A或Service_B使用InjectionToken:
export const SERVICE_TOKEN = new InjectionToken<Service_A | Service_B>('ServiceInjector');
...
export class BaseComponent {
constructor(
@Inject(SERVICE_TOKEN)
public service: Service_A | Service_B
) { }
}
Run Code Online (Sandbox Code Playgroud)
有两个扩展的组件BaseComponent:Component_A和Component_B。对于他们每个人,我想注入他们相应的服务。
如果我在组件级别使用 DI 提供程序,则效果很好:
@Component({
selector: 'ui-component-a',
templateUrl: `../base.component.html`,
providers: [{
provide: SERVICE_TOKEN,
useClass: Service_A
}]
})
export class Component_A extends BaseComponent { }
Run Code Online (Sandbox Code Playgroud)
@Component({
selector: 'ui-component-b',
templateUrl: `../base.component.html`,
providers: [{
provide: SERVICE_TOKEN,
useClass: Service_B
}]
})
export class Component_B extends …Run Code Online (Sandbox Code Playgroud) 我正在使用 Angular (6.0.9) 和 PrimeNG (6.0.1) 的最新稳定版本。当我尝试以编程方式将子节点添加到选定节点时,除非我折叠然后展开选定的父节点,否则它不会显示。首先我尝试过
this.selectedNode.children.push(this.nodeToAdd);
Run Code Online (Sandbox Code Playgroud)
然后我在官方文档中看到,如果“操作值,例如删除节点、添加节点或更改节点的子节点,而不是使用数组方法(例如push、splice),而是使用扩展运算符或类似操作创建新的数组引用”。所以我尝试了这个:
this.selectedNode.children = [...this.selectedNode.children, this.nodeToAdd];
Run Code Online (Sandbox Code Playgroud)
但它会导致相同的行为。有人面临同样的问题,还是我做错了什么?Chrome、Firefox 和 Edge 中均出现问题
I am using PrimeNg's context menu v6.0.1, the problem is the documentation is not clear and I cannot find it over the web as well on how to pass data to command function e.g.:
I have 10 objects rendered on screen and context menu is attached to all of these objects, now if I click on menu item I want to get the id of the target object on which the context menu is rendered, how can this be accomplished? …
我找不到任何方法将AuthService注入ErrorHandlerInterceptor中。它在注入后返回一个“未定义”对象,或者抛出一个错误。
这是我的ErrorHandlerInterceptor:
import { Injectable } from '@angular/core';
import { AuthService } from '@app/auth.service';
import { StorageService } from '@app/storage.service';
@Injectable({
providedIn: 'root'
})
export class ErrorHandlerInterceptor implements HttpInterceptor {
constructor(private authService: AuthService, private storageService: StorageService) {
console.log(this.authService); // undefined
}
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(request).pipe(catchError(error => this.errorHandler(error)));
}
// Customize the default error handler here if needed
private errorHandler(response: HttpErrorResponse): Observable<HttpEvent<any>>
{
// ... Various code
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的 …
我正在使用 Angular 6 开发一个应用程序。我有一个大问题。使用模板驱动的表单,我希望当我按下提交按钮时可以发送单选按钮中选择的项目。<input type="text" [(ngModel)] = "value" />当我使用(value是我组件的数据字段)时没问题,但是如果我尝试这样做:
<div class="form-group">
<div *ngFor = "let option of options">
<div class="radio">
<input type = "radio"
name = "radio"
[(ngModel)] = "value"
/>
<label for="{{option.id}}">{{option.id}}</div>
</label>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
结果是bug!我什至无法通过移动选择器来单击多个按钮!一切都卡住了!显然它不适用于表格。如果我以[(ngModel)] = "value"图形方式删除它,它可以工作,但如果没有 ngModel 指令,如果我在使用 (ngSubmit) 的模板驱动表单中输入此代码,它就不起作用。多谢。
我有一组可观察量,当最后一个提供了值(无论那个值是什么)时,我需要做出反应。
我的第一个方法是这样的forkJoin 。
const observables = [
this.backend.config(),
this.navigation.location()
];
forkJoin(observables)
.subscribe(([backend, selection]) => {
console.log(backend);
console.log(selection);
});
Run Code Online (Sandbox Code Playgroud)
只要可观察量在某个时刻发出完成(此时调用终结),这就会部分起作用。然后我尝试了mergeLatest 。这解决了原始问题,但创建了一个新问题。现在,只要有任何问题,我就会调用最终方法的可观察量提供。
我想在每个可观察对象至少提供一次并且可能已完成或尚未完成时调用它。它是每个值的最新值还是第一个值并不重要。尽管如此,学习如何控制它也可能是+1的一个优点。
我想出的最好但又很老套的解决方案是检查!!后端和!!导航,只有当它们全部满足时才采取行动。我正在寻找一种更顺畅的解决方案或确认我正在使用的解决方案是最好的。
combineLatest(observables)
.subscribe(([a, b, c]) => {
if (!a || !b || !c)
console.log("Oh, I'm coming...");
else
console.log("Wham, bam - I'm done!");
});
Run Code Online (Sandbox Code Playgroud)
所有这些内容都来自这样或那样的博客、 SO和Observables 文档上的帖子。
我正在尝试使用 Angular 6 中的 javascript 打开选择选项
const dropDown = document.getElementById(id);
let event;
event = document.createEvent('MouseEvents');
event.initMouseEvent('mousedown', true, true, window);
dropDown.dispatchEvent(event);
Run Code Online (Sandbox Code Playgroud)
也尝试过像
@ViewChild('select') select: ElementRef;
func() {
this.select.nativeElement.open();
}
Run Code Online (Sandbox Code Playgroud)
但它不起作用。我搜索并找到了材料和离子的结果。但是我怎样才能在 Angular 6 中打开呢?
如何更改ngx-paginationCSS?我尝试过:
:host /deep/ .ngx-pagination {
padding-left: 0px;
}
:host /deep/.ngx-pagination .current,
.btn-info {
background: #17a2b8 !important;
border: transparent;
border-radius: 20px;
}
:host /deep/.ngx-pagination .current:hover {
background: #17a2b8 !important;
border-radius: 20px;
border: transparent;
}
Run Code Online (Sandbox Code Playgroud)
在组件 .css 内部,但没有任何变化,我收到此警告
[弃用] CSS 动态配置文件中不再支持 /deep/ 组合器。它现在实际上是无操作的,就像一个后代组合器一样。/deep/组合器将被移除,并且在M65处无效。你应该删除它。有关更多详细信息,请参阅https://www.chromestatus.com/features/4964279606312960 。
我该如何解决这个问题?感谢您的时间!
编辑:
.html
<div class="clearfix">
<pagination-controls (pageChange)="p = $event"></pagination-controls>
</div>
Run Code Online (Sandbox Code Playgroud)
.css
.clearfix {
position: relative;
right: 35%;
left: 35%;
font-size: 14px;
}
Run Code Online (Sandbox Code Playgroud)
编辑2:(渲染后的html)
<div class="clearfix">
<pagination-controls nextlabel="Next" previouslabel="Previous" ng-reflect-previous-label="Previous"
ng-reflect-next-label="Next">
<pagination-template ng-reflect-max-size="7">
<!--bindings={
"ng-reflect-ng-if": "true" …Run Code Online (Sandbox Code Playgroud) 我正在开发一个 Web 应用程序,使用Angular 6 和 PrimeNG控件进行前端开发,使用ASP.Net Web API 和 SQL Server进行后端开发。
在我的一个表单中,有两个 PrimeNG Calender 控件用于将起始日期和结束日期保存到数据库中。提交表单后,所有表单字段都会被收集以填充对象/模型,并将该模型传递给 Web API。对象/模型是使用 Typescript 代码在 Angular 6 中填充的。下面是我的 Typescript 代码中的前端模型:
export class MyPackage {
public PackageId: number;
public PackageUid: number;
public PackageName: string;
public PackageDesc: string;
public ValidFrom: Date;
public ValidTill: Date;
public CreatedOn: Date;
}
Run Code Online (Sandbox Code Playgroud)
这是我使用 Angular 6 和 typescript 的对象初始化过程:
let pakg = new MyPackage();
pakg.PackageName = this.packageAddForm.controls["packageName"].value;
pakg.PackageDesc = this.packageAddForm.controls["packageDesc"].value;
pakg.ValidFrom = this.packageAddForm.controls["dateFrom"].value;
pakg.ValidTill = this.packageAddForm.controls["dateEnd"].value;
Run Code Online (Sandbox Code Playgroud)
现在的问题是,当模型传递到 Web API …
我在 Angular 项目中升级了我的 package.json 。迁移是从 Angular 6 到 7 完成的。当我尝试构建时,我在控制台中看到了这个错误。
错误 TS2563:包含的函数或模块主体太大,无法进行控制流分析。
这是我的新 package.json
{
"name": "e-case-prototype",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "node --max_old_space_size=4096 ./node_modules/@angular/cli/bin/ng serve --proxy-config proxy.conf.json --source-map=false",
"build": "node --max_old_space_size=5048 ./node_modules/@angular/cli/bin/ng build",
"build-prod": "node --max_old_space_size=5048 ./node_modules/@angular/cli/bin/ng build --prod",
"build-prod-aot-disabled": "node --max_old_space_size=5048 ./node_modules/@angular/cli/bin/ng build --prod --aot false --build-optimizer false",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular-devkit/build-angular": "^0.13.9",
"@angular/animations": "7.2.15",
"@angular/cdk": "7.3.7",
"@angular/common": "7.2.15",
"@angular/compiler": "7.2.15",
"@angular/core": "7.2.15", …Run Code Online (Sandbox Code Playgroud) angular6 ×10
angular ×6
typescript ×3
primeng ×2
angular7 ×1
datetime ×1
frontend ×1
html ×1
javascript ×1
observable ×1
rxjs ×1