Home > Net >  Could not find template file in typescript
Could not find template file in typescript

Time:12-06

enter image description here

am trying to call Html file into ts file. but I got file not find error.

please explain @Component

CodePudding user response:

@Component({
  selector: 'my-app',
  templateUrl: './jsonData.html',
  styleUrls: ['./app.component.css'],
})
export class AppComponent {
  title = 'Angular';
}

The selector should not contain the path because the selector is going to be used like this: <my-app></my-app> in some HTML template/file.

And coming to the templateUrl, it takes relative path to the HTML template. Since both the component and the template URL you're going to use are in the same folder, you can use ./ followed by the required file name.

That being said, it is better to name your files appropriately. app.component.ts, app.component.html, app.component.css

Hope this helps!

  • Related