Prakash sekar
Prakash sekar

Reputation: 29

Could not find template file in typescript

I am trying to call HTML file into TS file, but I see file not found error.

1

@Component({
  selector: 'app/jsonData.ts',
  templateUrl: 'src/app/jsonData.html',
})
export class AppComponent {
  title = 'Angular';
}

Please explain

Upvotes: 0

Views: 4251

Answers (1)

lifetimeLearner007
lifetimeLearner007

Reputation: 655

@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!

Upvotes: 2

Related Questions