问题描述
不确定发生了什么,为什么在更改上传位置时会弹出此错误.从本质上讲,我正在将一个组件从仅在一个组件中可以访问的整个组件更改为整个应用程序,现在我得到了该错误.
Not sure what's going on and why this error popped up when I changed where it was being uploaded. Essentially I am changing a component from being only accessible in one component to the whole app and now I get that error.
import { DefaultProfilePictureComponent } from '../sharedModules/components/default-profile-picture/default-profile-picture.component'
@NgModule({
declarations: [
...
DefaultProfilePictureComponent,
...
],
...
})
default-profile-picture.component.ts
@Component({
selector: 'app-default-profile-picture',
templateUrl: './default-profile-picture.component.html',
styleUrls: ['./default-profile-picture.component.scss'],
})
export class DefaultProfilePictureComponent implements OnInit {
@Input() private lastNames: string;
@Input() private big: boolean;
@Input() private contactBox: boolean;
private char1: string;
private char2?: string;
public constructor() {}
public ngOnInit(): void {
console.log(this.lastNames.split(' ').length);
if (this.lastNames.split('').length > 1) {
this.char1 = this.lastNames.split(' ')[0][0].toUpperCase();
this.char2 = this.lastNames.split(' ')[1][0].toUpperCase();
} else {
this.char1 = this.lastNames.split(' ')[0][0].toUpperCase();
}
}
}
default-profile-picture.component.html
<div class="profile-container" *ngIf="big">
<div class="profileImageBig">{{ char1 }} {{ char2 || '' }}</div>
</div>
home.page.html
<app-default-profile-picture
*ngIf="!person.profilePicture"
lastNames="person.lastNames"
contactBox="true"
></app-default-profile-picture>
在任何尝试使用该组件的地方,都会出现错误提示
anywhere I try and use the component I get the error saying
但是如果我将其包含在 home.page.module.ts
中,则会收到错误消息,指出它是在两个模块中声明的.是什么赋予了?谢谢!
but if I include it in the home.page.module.ts
then I get the error saying that it is declared in two modules. What gives? Thanks!
推荐答案
通过查看代码,您似乎已经在共享模块之类的另一个模块中创建并注册了该组件.
By seeing your code,It look like you have created and registered this component in another module like shared Module.
如果是这种情况,那么我建议您在应用程序模块中导入该共享模块,不要在应用程序模块内声明组件,只需导入共享模块即可.
If that is case then I will suggest you to import that shared Module in your app module and don't declare component inside app module ,just importing shared Module will do its work.
这篇关于错误未捕获的错误:在应用程序模块中声明时,模板解析错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!