I'm using angular 1.x with es6 and webpack, following this tutorial: http://angular-tips.com/blog/2015/06/using-angular-1-dot-x-with-es6-and-webpack/.
The author requires templates through template: require('./home.html')
.
I want to inject a template into a component via a controller through this method, but it's not working:
export default class MyController {
constructor() {
this.templateUrl = require('./templates/foo.html');
}
}
export const myComponent = {
bindings: {
templateUrl: '<'
},
template: '{{$ctrl.templateUrl}}'
}
This renders the html as a string, e.g. <p>Some template</p>
. I imagine there must be an easy way to remedy this problem without having to use ng-bind-html
.
I've also tried:
export default class MyController {
constructor() {
this.templateUrl = './templates/foo.html';
}
}
export const myComponent = {
bindings: {
templateUrl: '<'
},
template: require('{{$ctrl.templateUrl}}')
}
results in Cannot find module "{{$ctrl.panelUrl}}"
.