Angular Modernizer
    Preparing search index...

    Function loadComponentTemplate

    • Loads the template of an Angular component. This is the single entry point for reading a component template: it handles both template: literals and templateUrl: files, reads external files through the ts-morph file system (so in-memory projects work), and maps offsets back to line/column positions in the file that holds the text.

      Returns undefined when the class is not a component, declares neither template nor templateUrl, or the external file cannot be read.

      Parameters

      Returns ComponentTemplateSource | undefined

      const source = loadComponentTemplate(classDecl);
      if (source) {
      const { line } = source.locate(source.content.indexOf('*ngFor'));
      console.info(`${source.file}:${line}`);
      }