angularjs Could not find template file in typescript

qyswt5oh  于 2022-12-10  发布在  Angular
关注(0)|答案(1)|浏览(159)

我试图调用HTML文件到TS文件,但我看到文件找不到错误。

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

请解释一下

ycl3bljg

ycl3bljg1#

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

相关问题