我想在角度独立组件 v14 中使用ngx-avatar 。
我在模板中使用它,并在组件导入中导入它。
但我收到错误消息:
Component imports must be standalone components, directives, pipes, or must be NgModules.
Run Code Online (Sandbox Code Playgroud)
import { AvatarModule } from 'ngx-avatar';
@Component({
selector: 'my-app',
standalone: true,
imports: [AvatarModule, CommonModule],
template: `
app works!
<ngx-avatar class="my-avatar" value="HM"> </ngx-avatar>
`,
})
export class AppComponent {
name = 'Angular ' + VERSION.major;
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用它来解决它,importProvidersFrom但它不起作用:
bootstrapApplication(
AppComponent, {
providers: [importProvidersFrom(AvatarModule.forRoot())],
}
);
Run Code Online (Sandbox Code Playgroud)
知道我怎样才能让它发挥作用吗?
假设我有一个表格:-
searchForm = new FormGroup({
SearchBox = new FormControl<string>('', {nonNullable: true});
)}
Run Code Online (Sandbox Code Playgroud)
我尝试这样做:-
this.Query = this.searchForm.SearchBox.value;
Run Code Online (Sandbox Code Playgroud)
查询属性的类型是字符串,我收到错误。
“类型‘字符串|未定义’不可分配给类型‘字符串’”。
我可以使用!运算符使其像这样工作。
this.Query = this.searchForm.SearchBox.value!;
Run Code Online (Sandbox Code Playgroud)
但这是告诉它表单控件不会未定义的最好方法吗?有没有比打耳光更好的方法呢!我想在任何地方将表单控件的值分配给组件中的属性?
我正在开发一个 Angular 项目,从 angular14 更新到 15,但是在安装新的 Material 包后,整个项目在视觉上似乎被破坏了。颜色、边距、填充错误。该项目只包含css样式文件,不包含scss。我认为问题出在遗留材料组件上,但是我应该如何/在哪里添加到项目中?谢谢!
angular-material angular angular14 angular-migration angular15
我收到此错误错误:NG04014:路由“检查//”的配置无效:redirectTo 和 canActivate 不能一起使用。重定向发生在激活之前,因此 canActivate 永远不会被执行。将 Angular 13 升级到 14 后。有人可以帮忙吗?
我想知道如何将非独立组件导入到独立组件中,因为非独立组件是在 ngModule 中声明的。
我将我的 Angular 项目更新为 Angular 14。现在我想要一些standalone components,,pipes或者directives。
我有一个名为ProductModule的特色模块,并且希望在此模块中使用名为uppercase的独立管道。
// structure
---Product
---product.component
---product.service
---product.module.ts
---StandabloneFolder
---uppercase.pipe.ts
Run Code Online (Sandbox Code Playgroud)
我的大写管子
@Pipe({
name: 'uppercase',
standalone: true,
})
export class UppercasePipe implements PipeTransform {
transform(value: string): string {
return "UPPERCASE_INPUT"
}
}
Run Code Online (Sandbox Code Playgroud)
在product.component.html中
{{'Javascript Addicted' |uppercase}}
Run Code Online (Sandbox Code Playgroud)
出现以下错误:
找不到名称为“大写”的管道product.component.ts(6, 39):组件 ProductComponent 的模板中发生错误。
笔记:
standalone: true如果我添加到Product.Component并从声明数组中删除ProductComponent,这个问题就会得到解决。
默认情况下,Angular 14 应用程序(使用 构建angular-cli)仅支持 20% 的浏览器 ( browsersl.ist )。尽管阅读了相关文档,但我不清楚如何启用对旧版浏览器的支持。
.browserslistrc:默认情况下 angular-cli (v14) 生成此配置:
last 1 Chrome version
last 1 Firefox version
last 2 Edge major versions
last 2 Safari major versions
last 2 iOS major versions
Firefox ESR
Run Code Online (Sandbox Code Playgroud)
我已将其修改为以下内容。覆盖范围应从 20% 上升到 90%。然而,更旧的设备会显示“死机白屏”。
> 0.2%, not dead
Run Code Online (Sandbox Code Playgroud)
tsConfig.json这里 Angular cli (v14) 默认放置这些:
last 1 Chrome version
last 1 Firefox version
last 2 Edge major versions
last 2 Safari major versions …Run Code Online (Sandbox Code Playgroud) 我最近从 Angular12 迁移到 Angular14,Angular 在某些地方自动将 FormControl 转换为 UntypedFormControl。我观察到,在我使用 FormControl 的某些组件中,它仍然写为 FormControl。因此,我对哪些标准或在哪些条件下将 FormControl 角度转换为 UntypedFormControl 以及为什么在某些地方它仍然是 FormControl 感到有点困惑。我知道 UntypedFormControl 只是指向任何类型的 FormControl。
当我比较这两种情况时,我没有发现编码以及创建和使用 formGroup 和 formControl 的方式有任何差异。这让我更加困惑。
提前致谢!
formbuilder form-control formgroups angular14 angular-migration
在使用最新版本的 Angular(版本 14)时,我似乎没有做得很好,因此严格类型化的反应式表单无法按预期工作。
表单是ngOnInit使用injected在内部初始化的FormBuilder。
public form!: FormGroup;
constructor(private formBuilder: FormBuilder) {}
ngOnInit(): void {
this.initializeForm();
}
private initializeForm(): void {
this.form = this.formBuilder.group({
title: ['', [Validators.required, Validators.minLength(3)]],
content: ['', Validators.required],
});
}
Run Code Online (Sandbox Code Playgroud)
现在,当我尝试访问表单的控件时,没有自动完成功能,类型为FormGroup<any>。此外,当尝试访问对象上不存在的控件时,它不会引发错误FormGroup。
package.json在删除项目中的所有错误后,我从 Angular 7 更新到 Angular 14,这是阻止我成功编译的唯一错误。我在 ng 服务上收到此错误:
/src/app/shared/styles/themes/theme-f.scss:1:6 - 错误:模块解析失败:意外的标记 (1:6) 文件已使用这些加载器处理:*/node_modules/resolve-url-loader /index.js */node_modules/sass-loader/dist/cjs.js 您可能需要一个额外的加载器来处理这些加载器的结果。正文,.wrapper > 部分 { | 背景颜色:#f5f7fa;| 颜色:#73879C;
这是我的 tsconfig.json 文件
{
"compileOnSave": false,
"compilerOptions": {
"strictPropertyInitialization": false,
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "es2020",
"moduleResolution": "node",
"experimentalDecorators": true,
"importHelpers": true,
"target": "es2019",
"skipLibCheck": true,
"typeRoots": [
"node_modules/@types"
],
"types": [ "googlemaps" ],
"lib": [
"es2018",
"DOM",
"DOM.Iterable",
//"ScriptHost"
]
},
"angularCompilerOptions": {
//"enableLegacyTemplate": true,
//"enableI18nLegacyMessageIdFormat": false,
"disableTypeScriptVersionCheck": true,
"strictInjectionParameters": true,
"strictInputAccessModifiers": true, …Run Code Online (Sandbox Code Playgroud)angular14 ×10
angular ×9
angular15 ×2
angular-standalone-components ×1
css ×1
form-control ×1
formbuilder ×1
formgroups ×1
forms ×1
loader ×1
node-sass ×1
polyfills ×1
routes ×1
typescript ×1