我在用FormGroupDirectivein测试组件时遇到了一些问题viewProviders。无法创建模拟parent并设置空的 formGroup。
我的组件:
@Component({
(...)
viewProviders: [
{
provide: ControlContainer, useExisting: FormGroupDirective
}
]
})
export class SomeNestedFormComponent implements OnInit {
form: FormGroup;
constructor(private fb: FormBuilder, private parent: FormGroupDirective) {}
ngOnInit() {
this.form = this.parent.form;
this.form.addControl('field', this.createSomeFormGroup());
}
}
Run Code Online (Sandbox Code Playgroud)
规格:
describe('SomeNestedFormComponent', () => {
let component: SomeNestedFormComponent;
let fixture: ComponentFixture<SomeNestedFormComponent>;
let formGroupDirective: Partial<FormGroupDirective>;
beforeEach(async(() => {
formGroupDirective = {
form: new FormGroup({})
};
TestBed.configureTestingModule({
imports: [
SharedModule,
FormsModule,
ReactiveFormsModule
],
declarations: [SomeNestedFormComponent],
providers: [] …Run Code Online (Sandbox Code Playgroud) 这可能是一个愚蠢的问题,但我无法弄清楚如何在 vscode 或 vs2019 社区中调试我的整个应用程序。如果我使用vs2019,我可以很好地调试api,控制器等,但无法调试typescript或js。如果我使用 vscode,我可以调试打字稿,但它不会调用 api,因此应用程序锁定...
有什么建议?我已经在 vscode 中尝试了 google 扩展,但仍然无法调试打字稿代码。
提前致谢。
single-page-application visual-studio-code angular7 visual-studio-2019
使用概念字典我想做以下任务。
1. Closed
2. Open
3. Cancelled
4. Rejected
5. Saved
6. Draft
7. Pending Approval
Run Code Online (Sandbox Code Playgroud)
这是不同的状态。现在我的表如下
Purchase Order Status
PO1 closed
PO2 pending_approval
PO3 open
PO4 Draft
PO5 Cancelled
PO6 Rejected
PO7 Saved
Run Code Online (Sandbox Code Playgroud)
现在我需要使用徽章以不同颜色显示每个状态
使用的方法是字典法。
谁能告诉我什么是字典法?(简要说明)
也请给我解决方案
当用户点击ion-back-button时,我想停止从一个页面导航到另一个页面。我有一些验证/检查要执行,具体取决于哪个应用程序将决定是否允许后退操作。
在具有“useHash: true”路由器模块配置的 Angular 7 单页应用程序中,我需要生成要在新选项卡中打开的资源的 url。
对于应用程序窗口中的路由,以下代码按预期工作:
this.router.navigate(['foo', 1]);
这意味着,它生成的 url 如下: http://localhost:4200/#/foo/1
虽然使用以下方法时: const url = this.router.createUrlTree(['foo', 1]).toString();
url 是“/foo/1”——没有“#”,所以...
window.open(url, '_blank'); 结果与无效的网址:
我发现的唯一解决方案(黑客)非常残酷:
window.open('#' + url, '_blank');
RouterModule.forRoot(routes, {
useHash: true,
onSameUrlNavigation: 'reload',
}
Run Code Online (Sandbox Code Playgroud)
showItem(item: Item) {
// THIS WORKS AS EXPECTED
this.router.navigate(['item', item.id]);
}
showItemInNewTab(item: Item) {
const url = this.router.createUrlTree(['item', item.id]).toString();
// THIS WORKS BUT ITS A HACK :/
window.open('#' + url, '_blank');
}
Run Code Online (Sandbox Code Playgroud) Angular5:需要构建一个应用程序,其中必须在文本区域内显示 TextArea 字符数,而不是外部。
找到多种显示字符数的方法,我能够做到这一点,但是是否有可能如何在TextArea 内显示该字符数?
代码:HTML 文件
<td>
<textarea pInputTextArea [(ngModel)]="value" (ngModelChange)="valueChange(value)" maxlength="1000"></textarea>
<span>{{remainingText}}</span>
</td>
Run Code Online (Sandbox Code Playgroud)
.ts 文件
valueChange(value) {
this.remainingText = 1000 - value;
}
Run Code Online (Sandbox Code Playgroud) 我使用 Angular 8。
这个问题仅适用于 Angular DI 专家。
首先,我制作了一个 Angular 库,将在许多项目中重用。
在这个库中,我创建了一个抽象服务,必须在使用它的项目中定义该服务。
我在我的库中定义了一个名为 BridgeService 的抽象类
在我的主项目中,我创建了 BridgeService 来实现它:(在接下来的几行中,我将向您展示抽象的 BridgeService)
主要项目 > BridgeService :
import { BridgeService as AbstractBridgeService } from 'myLibrary';
@Injectable()
export class BridgeService implements AbstractBridgeService {
hello(){
alert('hello Word');
}
}
Run Code Online (Sandbox Code Playgroud)
主项目>用户模块:
import { UsersModule as LibraryUsersModule } from 'myLibrary';
@NgModule({
imports: [
CommonModule,
LibraryUsersModule,
],
//...
providers: [
BridgeService
// some try:
//{ provide: BridgeService, useClass: BridgeService }
],
})
export class UsersModule {
constructor(private bridgeService: BridgeService){
this.bridgeService.hello(); …Run Code Online (Sandbox Code Playgroud) angular angular-dependency-injection angular7 angular8 angular9
我想压缩构建angular项目时创建的包文件.我ng build --environment=${environment}用来构建当前的应用程序和版本"@angular/compiler-cli": "^4.0.0"不生成.gz文件到dist文件夹.生成.gz包文件的最简单方法是什么(最好不要触摸webpack.config.js文件)?PS:我知道.gz有时创建文件的选项会被angular/cli团队删除.但我绝望地需要它,因为我的捆绑文件非常庞大.
我收到致命错误:CALL_AND_RETRY_LAST分配失败 - Angular 7.1升级后JavaScript堆内存不足.以前的版本6.1工作得非常好.
我在运行ng build --prod命令时仅在Azure DevOps中收到错误.它在当地建造完美.
以下是详细日志.知道我为什么会收到这个错误吗?
2018-11-22T06:40:36.2804965Z ##[section]Starting: npm build
2018-11-22T06:40:36.2809301Z ==============================================================================
2018-11-22T06:40:36.2809365Z Task : npm
2018-11-22T06:40:36.2809456Z Description : Install and publish npm packages, or run an npm command. Supports npmjs.com and authenticated registries like Package Management.
2018-11-22T06:40:36.2809496Z Version : 1.0.27
2018-11-22T06:40:36.2809531Z Author : Microsoft Corporation
2018-11-22T06:40:36.2809612Z Help : [More Information](https://go.microsoft.com/fwlink/?LinkID=613746)
2018-11-22T06:40:36.2809648Z ==============================================================================
2018-11-22T06:40:36.7158800Z SYSTEMVSSCONNECTION exists true
2018-11-22T06:40:36.8019327Z SYSTEMVSSCONNECTION exists true
2018-11-22T06:40:36.8872807Z [command]C:\Windows\system32\cmd.exe /D /S /C ""C:\Program Files\nodejs\npm.cmd" --version"
2018-11-22T06:40:37.5174051Z 6.4.1
2018-11-22T06:40:38.9461529Z …Run Code Online (Sandbox Code Playgroud) 我最近在使用ng update
和运行时更新了我的angular版本ng lint
我收到错误 create is deprecated: use new Observable() instead
this.data$ = Observable.create(t => {
t.next(this.model);
t.complete();
});
Run Code Online (Sandbox Code Playgroud)
new observable的语法是什么?
angular7 ×10
angular ×9
typescript ×2
angular-cli ×1
angular-dependency-injection ×1
angular5 ×1
angular6 ×1
angular8 ×1
angular9 ×1
azure-devops ×1
compression ×1
gzip ×1
ionic4 ×1
javascript ×1
npm ×1
unit-testing ×1