I am playing around in Ionic and would like to insert custom html into the view, that would also have directives such as ng-if
, is that possible?
Example: I'd like to have a service that displays a dialog window with custom text anywhere in the app = it would just inject it into the view when needed.
Currently I have <div ng-bind-html="dialogWindow"></div>
in my sidemenu from the Ionic template as that is an abstract state and the controller + view is accessible everywhere.
Then I have this in the main controller - $rootScope.dialogWindow = '';
And the services
angular.module('starter.services')
.factory('$dialogs', ['$htmlInjector', function ($htmlInjector) {
return {
show: function (type) {
if (type === 'type_a') {
var template = '' +
'<div class="overlay" ng-if="condition" ng-click="doSomething()"></div>' +
'<div class="dialog">Test Controller</b>' +
'';
$htmlInjector.add(template, 'dialog');
}
}
}
}]);
and then
angular.module('starter.services')
.factory('$htmlInjector', ['$rootScope', function ($rootScope) {
return {
add: function (html, element) {
if (element === 'dialog') {
$rootScope.dialogWindow = html;
}
}
}
}]);
So this works so far but the template gets sanitised if that's the right term and so no directives are available :( What is a better way of doing this? My idea is to inject the html node only when needed and into any view, not just in the main one ( I am doing that because that way i can display the dialog on any screen page).
Thanks