【问题标题】:How to fix problem on import one custom component如何解决导入一个自定义组件的问题
【发布时间】:2022-07-21 22:46:40
【问题描述】:

我尝试在其他组件中简单地导入自定义组件,但出现错误“找不到模块”

Cannot find module 'src/app/Aliase/index' or its corresponding type declarations.

5 import { IndexComponent as AliaseIndex } from 'src/app/Aliase/index'

我在 ngmodel 中有导入

import { CreateComponent as AliaseCreateComponent  } from './Aliase/create/create.component';
import { IndexComponent  as AliaseIndexComponent   } from './userJamesAliase/index/index.component';
import { ViewComponent   as UserViewComponent    } from './user/view/view.component';
@NgModule({
  declarations: [AliaseIndexComponent,AliaseIndexComponent,UserViewComponent    
const routes: Routes = [
  { path: 'Aliase', redirectTo: 'Aliase/index', pathMatch: 'full'},
  { path: 'Aliase/index', component: IndexComponent },
  { path: 'Aliase/create', component: CreateComponent },
 
];
export const userJamesAliaseRoutingModule: ModuleWithProviders<any> = RouterModule.forChild(routes);

我也更改了文件tsconfig.json

import { AliaseIndexComponent} from 'src/app/Aliase/index';

     
@Component({
  selector: 'app-view, [adHost]',
  templateUrl: './view.component.html',
  styleUrls: ['./view.component.scss']
})
export class ViewComponent implements OnInit {
      
  // @ViewChild(AdDirective,{static: true}) adHost!: AdDirective;
  id!: string;
  user!: User;
     
  constructor(
    public userService: UserService,
    private route: ActivatedRoute,
    private router: Router,
    public viewContainerRef: ViewContainerRef
   ) { }
     
 
  ngOnInit(): void {
    this.id = this.route.snapshot.params['userId'];
    this.userJamesService.find(this.id).subscribe((data: any)=>{
      this.user = data;

    });
  }
     
}
@Component({
  selector: 'app-index',
  templateUrl: './index.component.html',
  styleUrls: ['./index.component.scss']
})
export class IndexComponent implements OnInit {
       
  @Input() username!: string;
  aliases: Aliase[] = [];

     
  
  constructor(public aliaseService: AliaseService) { }
     
 ...
}

我需要导入这个组件来动态加载第二个组件,compose的重命名有问题吗?

【问题讨论】:

  • 你能分享一下CreateComponent/IndexComponentcomponent.ts 文件中写的内容吗?

标签: angular


【解决方案1】:

您可以使用此命令来跟踪问题:

tsc --traceResolution

【讨论】:

  • 我的命令未知
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-01
  • 2019-06-05
相关资源
最近更新 更多