I am trying to create some Bootstrap modals dynamically using AngularJS, as described in here: https://angular-ui.github.io/bootstrap/
For that purpose, I have created a basic script template in AngularJS inside a view of a directive called modalView.html:
<script type="text/ng-template" **id="{{modalId}}.html"**>
<div class="modal-header">
Header
</div>
<div class="modal-body">
Body
</div>
<div class="modal-footer">
Footer
</div>
</script>
And this is my directive (modalDirective.js):
myDirectives.directive('modal', function () {
return {
restrict: 'A',
scope: {},
templateUrl: 'shared/controls/modal/modalView.html',
link: function (scope, element, attributes) {
scope.modalId = attributes['modalId'];
}
}
});
Then, I have another directive that uses the aforementioned directive alongside a textbox that should open the modal when the latter is clicked.
modalTextboxView.html:
<div modal modal-id="{{modalId}}"></div>
<div textbox is-read-only="true" ng-click="openModal()"></div>
modalTextboxDirective.js:
myDirectives.directive('modalTextbox', function ($modal, $log) {
return {
restrict: 'A',
scope: {},
templateUrl: 'shared/controls/modalTextbox/modalTextboxView.html',
link: function (scope, element, attributes) {
scope.modalId = attributes['fieldId'];
scope.openModal = function(modalSize) {
var modalInstance = $modal.open({
**templateUrl: scope.modalId + '.html',**
size: modalSize,
resolve: {
items: function () {
return scope.items;
}
}
});
modalInstance.result.then(function (selectedItem) {
scope.selected = selectedItem;
}, function () {
$log.info('Modal dismissed at: ' + new Date());
});
}
}
}
});
The html output is as expected. I can see that the script template id of the first view is being set correctly. However, when I click on the textbox I get an error 404. It seems that the modal is trying to be opened but can't find the templateUrl defined, which has been set correctly too. Moreover, if I just type the hardcoded value into the id field of the script template it works flawlessly and it opens the modal. Unfortunately, I need that id to be dynamic as I need to be able to create and generate an undetermined number of modals on my page.
Any ideas?