如何使用当前的 Angular-cli 版本(Angular 6)安装以前版本的 Angular 项目。
我找到了一个命令,但已弃用:
ng new my_project --ng4
我有一个使用 ComponentFactoryResolver 动态创建的组件
this.container.clear();
let factory = this.resolver.resolveComponentFactory(DynamicComponent);
this.componentRef = this.container.createComponent(factory);
template: '...<child-component [param1]="param1"></child-component>...';
Run Code Online (Sandbox Code Playgroud)
问题是 DynamicComponent 的模板有子组件和输入绑定。有没有办法在动态创建组件时将参数传递给子组件?
我正在构建一个应用程序,该应用程序将使用(很可能)其他应用程序也会使用的库。在 Angular 6 中,创建一个新库就像ng g library MyLibrary. 构建您的库,使其可在您的应用程序中使用ng build MyLibrary。最后,根据文档,您可以像import { SomethingFromMyLibrary } from 'MyLibrary';在 app.module.ts 文件中导入任何其他库一样导入您的库。我的问题是,为什么这对我不起作用?我收到错误Cannot find module 'AbsenceMonitorCore'对于我的情况,具体的导入语句是import { AbsenceMonitorCoreModule } from 'AbsenceMonitorCore';
这是我的库模块:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule } from '@angular/router';
import { FormsModule } from '@angular/forms';
import { AbsenceMonitorCoreComponent } from './absence-monitor-core.component';
import { AbsencesComponent } from './components/absences/absences.component';
import { SigninComponent } from './components/signin/signin.component';
import …Run Code Online (Sandbox Code Playgroud) 我想创建一个自定义通用验证器,它将通过参数传递正则表达式的模式和要检查的属性(表单组)的名称。我有以下代码
UserName: new FormControl('',
[
Validators.required,
Validators.minLength(8),
this.OnlyNumbersAndLetterValidator(/^[a-zA-Z0-9]+$/, "UserName")
]
)
OnlyNumbersAndLetterValidator(regexPattern: RegExp, propertyName: string): ValidatorFn {
return (currentControl: AbstractControl): { [key: string]: any } => {
if (!regexPattern.test(currentControl.value)) {
return { propertyName: true }
}
}
}
Run Code Online (Sandbox Code Playgroud)
问题是当表达式无效时,返回"{propertyName: true}",而不是"{UserName: true}",有什么问题?
我已经创建了一个新的.net core 2.1应用程序angular template,之后我更新了要使用的项目Angular 6.
请注意,该项目与angular cli生成的项目几乎相同
我的项目将有很多组件和服务,因此我不想使用相对路径,而是希望能够使用非相对路径
import { WeatherService } from '../../services/weather.service'
Run Code Online (Sandbox Code Playgroud)
我希望能够使用非相对路径,如:
import { WeatherService } from '@app-services/weather.service'
Run Code Online (Sandbox Code Playgroud)
所以我补充道
"baseUrl": ".",
"paths": {
"@app-services/*": [ "src/app/services/*" ]
},
Run Code Online (Sandbox Code Playgroud)
进入 tsconfig.json
整个配置:
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"baseUrl": ".",
"paths": {
"@app-services/*": [ "src/app/services/*" ]
},
"lib": [
"es2017",
"dom"
]
}
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用该组件<ng2-smart-table>。我确实做到了,但是我需要在用户单击页面或列进行排序后刷新数据,有什么方法可以捕获这些事件并刷新数据?
table.component.html
<ng2-smart-table
[settings]="settings"
[source]="characters">
</ng2-smart-table>
Run Code Online (Sandbox Code Playgroud)
表.service.ts
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Injectable()
export class TableService {
constructor(private http: HttpClient) { }
url = 'http://localhost:4000';
getCharacters() {
return this
.http
.get(`${this.url}/characters`);
}
}
Run Code Online (Sandbox Code Playgroud)
表.interface.ts
export interface Table {
ticket: String;
title: String;
state: String;
owner: String;
age: String;
priority: String;
}
Run Code Online (Sandbox Code Playgroud)
table.component.ts
import { Component, OnInit } from '@angular/core';
import { TableService } from './table.service';
import { Table } from './table.interface'; …Run Code Online (Sandbox Code Playgroud) 我已输入数据用户详细信息first_name,last_name,phone_number和profile_pic但文件未上传其他表单数据如何上传其他表单数据文件?
用户form.component.ts
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { Router } from '@angular/router';
import { HttpClient } from '@angular/common/http';
import { UserService } from '../user.service';
import { FileUploader, FileSelectDirective } from 'ng2-file-upload/ng2-file-upload';
@Component({
selector: 'user-form',
templateUrl: './user-form.component.html',
styleUrls: ['./user-form.component.scss']
})
export class UserFormComponent {
angForm: FormGroup
router: Router;
constructor(private userservice: UserService, private fb: FormBuilder, private _route: Router) {
this.createForm();
this.router = _route;
}
createForm() {
this.angForm = this.fb.group({
first_name: ['', …Run Code Online (Sandbox Code Playgroud) 我最近将我的 Angular 5 项目更新为 Angular 6,并且我一整天都在尝试构建和部署。我的最新问题是导入问题 - 之前工作正常。
错误现在cannot find module 'firebase'在我的导入中说。
我正在使用有角度的树材料来显示 JSON 数据,我对行之间的白色间距数量不满意。我尝试mat-tree-node.line-height在 css 中进行零更改。如何减少所有这些垂直空白?
我想使用Spring Application的GET请求在Angular应用程序中显示HashMap.我试过这个:
春天代码:
@GetMapping("gateways")
public ResponseEntity<?> getGateways() {
Map<Integer, String> list = new HashMap<>();
list.put(1, "Bogus");
return ok(list.put);
}
Run Code Online (Sandbox Code Playgroud)
角度服务:
getContractGatewaysList(): Observable<Array<ContractGatewaysList>> {
return this.http.get<Array<ContractGatewaysList>>(environment.api.urls.contracts.getContractGateways);
}
Run Code Online (Sandbox Code Playgroud)
角度成分:
gateways: ContractGatewaysList[];
this.contractService.getContractGatewaysList()
.subscribe(value => {
if (value != null) {
this.gateways = value;
}
});
Run Code Online (Sandbox Code Playgroud)
接口:
export interface ContractGatewaysList {
id: number;
name: string;
}
Run Code Online (Sandbox Code Playgroud)
HTML代码:
<div class="form-group gateway">
<div class="input-group-prepend">
<label for="merchant_id">Gateway</label>
</div>
<select class="custom-select" name="gateway" [(ngModel)]="contract.gateway" id="gateway" required>
<option selected>Please Select...</option>
<option [value]="gateway.id" *ngFor="let gateway of gateways">{{ gateway.name }}</option>
</select> …Run Code Online (Sandbox Code Playgroud)