I'm trying to create dynamic modals in Angular 2 using the ng2-bs3-modals. I would like to fill in the modal html body text dynamically based on the parameter passed to the selector used in the main component's view. When I use this code however it seems to treat my entire function as text and so my modal displays the code of my 'function determineModalContent' rather than the intended behavior which is to display the contents of the file.
I also know that my code won't return the contents of the file, just the string but I haven't yet figured out how in Angular2/TypeScript to read in the file contents.
import { Component, Input } from 'angular2/core'
@Component({
selector: 'static-modal',
template: '{{modalBody}}'
})
export class StaticModalComponent {
@Input() modalID;
template = 'app/shared/modals/static-message-1.html'
modalBody = function determineModalContent(modalID){
if(modalID == "1")
return 'app/shared/modals/static-message-1.html';
else if(modalID == "2")
return 'app/shared/modals/static-message-2.html';
else
return 'app/shared/modals/static-message-default.html';
}
}