0

Summary

I'm trying to convert my angularjs components/directives over to TypeScript. Unfortunately, the templateUrl property doesn't display the template that's passed to it. Instead, it literally displays a partial path the template.

Code

class JumpPagerController {
...
    }
}

JumpPagerController.$inject = ['$timeout'];
export const jumpPagerComponent = {
    templateUrl: './jump-pager.component.html',
    controller: JumpPagerController,
    bindings: {
        pagerPlaceholder: '@?',
        pagerCurrentPage: '=',
        pagerItemsPerPage: '=',
        pagerTotalItems: '=',
        pagerChange: '&'
    }
};

Expected

enter image description here

Actual

enter image description here

What I've Tried

  • Passing in the baseUrl (didn't have high hopes here:
    • templateUrl: `${baseUrl}/jump-pager.component.html`
    • templateUrl: localhost:8080/jump-pager.component.html
  • template: require('...') works, but would require me to reconfigure webpack and then modify all other cases of templateUrl in .js files. This isn't an option
  • I've reviewed similar questions but no one else seems to be having quite the same issue. They're all either using JavaScript instead of TypeScript, or they're only having an issue with the template not rendering and don't seem to be getting the weird problem with the template path being displayed.

Recap

So you can see that I'm at a loss. What is the correct way to use templateUrl on an angularjs component using typescript and webpack?

4
  • Using a / prefix will make the path relative to the domain, if that's where the file really is—have you tried this? (i.e. /jump-pager.component.html) Though something tells me you've got this template file nested in a folder for the component. Commented Jun 14, 2019 at 3:16
  • I am considering html and ts is in same folder. So you can directly use 'jump-pager.component.html' Commented Jun 14, 2019 at 5:44
  • The assumptions are correct. All the components .ts/.scss/.html live in their respective folders, so the assumption would be ./jump-pager.component.html or jump-pager.component.html would work. Commented Jun 14, 2019 at 15:13
  • On a side note, I found a way to use template: require('./jump-pager.html') in my TypeScript without breaking other components still written in JavaScript by adding a second html-loader configuration in my webpack.config.js. One has issuer: /\.js$/ and the unchanged configuration, while the other one has issuer: /\.ts$/ with the recommended boilerplate configuration for html-loader. It seems to work as expected. Commented Jun 14, 2019 at 15:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.