I have the controller that loads template from the server. Controller receives the template by http and compiles it to the valid html. All is fine but js-calls.
My template contains href's/buttons with href-javascript/onclick actions. Here is simplified snippet:
/*global angular */
var app = angular.module("app", ["ngSanitize"]);
app.controller('app.core.ctrl', function($scope, $rootScope, $interpolate) {
"use strict";
$scope.check = 1;
$scope.fetchContent = function() {
$scope.content = $interpolate(
'<a href="http://example.com">not interesting link</a>'+
'<a href="javascript:callSuperLogic();"> My business template link {{check}}</a>' +
'<button onclick="callSuperLogic();"> My business template button {{check+1}}</button>'
)($scope);
};
$scope.fetchContent();
});
var callSuperLogic = function() {
"use strict";
alert('It works!!!');
};
a,
button {
display: block;
}
div {
border: 1px solid #A6A6A6;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular-sanitize.min.js"></script>
<div ng-app="app">
<div ng-controller="app.core.ctrl">
My template calls:
<div ng-bind-html="content"></div>
</div>
</div>
I've tried $sce.trustAsResourceUrl('javascript:callSuperLogic();');
but it didn't help.
Is there any way to call js-event from compiled template?
UPD1: Found workaround: ng-include This behaves as predicted. But this way I can not make any error processing.