is it possible to create a AngularJS Component with a dynamic templateUrl? Means I want to inject a service into the Component that gives me a base path to the template:
i.e.: templateUrl: configuration.baseScriptPath + '...html'
It is possible with a Directive, but how to do this with a Component?
angular.module('runtime')
.component('textInput', {
templateUrl: /*configuration.baseScriptPath + */'fd/components/text_input_instance.html',
controller: [
'$scope', '$element', 'focusInputGroup', 'configuration',
function ($scope, $element, focusInputGroup, configuration) {
Instead of templateUrl you can use template and ng-include
, like this:
angular.module('runtime')
.component('textInput', {
template: '<div ng-include="getTemplate()">',
controller: [
'$scope', '$element', 'focusInputGroup', 'configuration',
function ($scope, $element, focusInputGroup, configuration) {
$scope.getTemplate = function () {
return configuration.baseScriptPath + 'fd/components/text_input_instance.html';
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With