Home > Blockchain >  Angular Where am I supposed to write my typescript?
Angular Where am I supposed to write my typescript?

Time:10-28

Do I write it in main.ts and then compile it? Because if yes, it does not work for me for some reason. Here is my index.html:

<!doctype html>
<html lang="en">
<head>
    `your text`<meta charset="utf-8">
    <title>Testing</title>
    <base href="/">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root></app-root>
</body>
</html>

app.component.html:

<button >Click</button>

main.js:

const btn = document.querySelector('.btn')
btn?.addEventListener("click", function() {
    btn?.style.width = '100px'
}

I am 100% sure it's an incredibly dumb question, but the button basically does nothing and I have no idea why.

CodePudding user response:

The right place to add your components code is in *.component.ts. So in this case, app.component.ts.

I strongly advise you to read the docs and make a tutorial: https://angular.io/tutorial

CodePudding user response:

To answer your question in short, there should be some Typescript files in there, if you're referring to Angular and not AngularJS.

The easiest way to get started is going to be to create a new skeleton project using the Angular CLI: https://angular.io/cli especially if you're not familiar with how the files work together. This is going to give you an already fully functional project, with all the correct files created, and then you have something to start from.

I would start with installing the CLI with the link above, and then going to your projects folder and typing these commands:

ng new my-first-project
cd my-first-project
ng serve

Once you've done that, you'll see that the project is running, and has all the files you need, and you can start modifying.

Take a look at the docs at the link I provided above, they're very helpful.

  • Related