-2

In my angular project , i have 4 components (comp1,comp2,comp3,comp4), i found a code of form (html , css & js ) and i wanna put it in comp1, so tell me if i'm right or not : do i put the html form code in comp1.component.html? and do i put the css and js codes in app.component.html or comp1.component.css & comp1.component.ts in order ?

I have added the html code in comp1.component.html, the css code in comp1.component.css and the script code in comp1.component.ts but there are some errors.

1 Answer 1

1

The error you are having is that you are trying to use JS code into TS file. If you put .js code into a .ts file you will have type errors.

Not quite sure about this, but you should have in mind that the component.css should contain only code that is going to use for that specific component. If not you can create a new .css file and import it into your project. Same logic for the rest of the files. If you are using angular versions from 2 to 16 have in mind that in your app.component.ts should contain only roots, imports, etc. The code you want to use for specific component should go to that specific component and never to the app.component.

Sign up to request clarification or add additional context in comments.

Comments

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.