Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Two component.ts files point towards same component.html file

I’m trying to split my functions inside my first.component.ts file to another second.component.ts file make it more readable.

I am pointing to the same component.html file from both ts files like this:

first.component.ts

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

@Component({
  selector: 'first-component',
  templateUrl: './main.component.html',
  styleUrls: ['./main.component.scss'],
})

second.component.ts

@Component({
  selector: 'second-component',
  templateUrl: './main.component.html',
  styleUrls: ['./main.component.scss'],
})

By doing this, I get errors that functions that are in the second component are missing in the first component and that other way around. This is because when I use the functions in the HTML they check for them in both of the .ts files.

What can I do to prevent this?

>Solution :

Those are two separate components.

Just because you declare the same template does NOT mean it merges them into a single one.

If you want to split your code for more readability, then use the Anguar features to do so : services, directives, pipelines, Input/Output …

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading