1

I am facing the problem in angular 4.4 , In my app, I have hierarchical view. In which I have created a

:= module 1 -> module 2 -> my component.

I have declared everything correctly. , But still I'm getting error.

  1. Declared component.
  2. Imported it into other module.
  3. selector name is same.
  4. Exported component in module 2.
  5. Imported module 2 in module 1.

What could be the catch? Component Code: Admin -> Configuration -> mycomponent //My component

import { Component, OnInit, ViewChild, ChangeDetectorRef } from '@angular/core';
@Component({
  selector: 'test-mycomponent',
  templateUrl: './mycomponent.component.html',
  styleUrls: ['./mycomponent.component.scss']
})
export class MyComponentComponent implements OnInit {
  @ViewChild('myComponentTable')

  constructor() {
    }
  ngOnInit() {
//init functionality
}
}

// configure module code 
import { NgModule,Component } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { MyComponentComponent } from './mycomponent/mycomponent.component';
@NgModule({
  imports: [
    CommonModule,
    WidgetsModule,
    FormsModule,
    NgbModule
  ],
  declarations: [
    MyComponent
  ],
  providers: [
  ],
  exports: [
    MyComponent
  ]
})
export class ConfigurationModule { }

//Main module admin
import { NgModule, Component } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ConfigurationModule } from './configuration/configuration.module';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { MyComponentComponent } from './configuration/mycomponent/mycomponent.component';
import { FormsModule } from '@angular/forms';
@NgModule({
  imports: [
    CommonModule,
    NgbModule,
    FormsModule,
    ConfigurationModule
  ],
  declarations: [
  ],
  exports: [
     ]
})
export class AdminModule { }

and I am calling that template in another file
//Test file html 
    <ng-template>
          <test-mycomponent></test-mycomponent>
      </ng-template> 
2
  • 1
    can you please add code .. Commented Dec 11, 2017 at 4:59
  • @AmolRaje Plz check Commented Dec 11, 2017 at 5:56

1 Answer 1

1

You are not declaring the right component the name should be MyComponentComponent in the declerations and exports:

import { MyComponentComponent } from './mycomponent/mycomponent.component';

declarations: [
    MyComponent //should be MyComponentComponent 
  ],
  providers: [
  ],
  exports: [
    MyComponent //should be MyComponentComponent 
  ]
Sign up to request clarification or add additional context in comments.

1 Comment

I have corrected that in my code, but still the same error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.