У меня есть простое угловое приложение, и я пытаюсь добавить HTML-код на страницу с помощью ngBindHtml. Однако его не вводят. Вот мой HTML:
<main id="main" ng-bind-html="oreGen | trust"></main>
И вот мое угловое приложение:
angular.module('programApp', ['programApp.controllers','programApp.filters','ngSanitize']);
angular.module('programApp.controllers', [])
.controller('programController', ['$scope', '$filter', function($scope, $filter){
$scope.oreGen = '<div class="oreFunction" ng-click="collectFunction(\'parenthesis\', 1)">test text</div>';
$scope.collectFunction = function(value1, value2){
alert(value1 + value2);
};
}]);
angular.module('programApp.filters', []).filter('trust', ['$sce', function($sce){
return function(text) {
return $sce.trustAsHtml(text);
};
}]);
Когда страница загружается, внутри основного элемента ничего не появляется.
Вот кодовая ручка: http://codepen.io/trueScript/pen/MwbVpO?editors=101
Вы можете видеть, что div, являющийся ngBinded, не отображается. Почему это?
ng-app
в вашем HTML-коде.. похоже, вы его пропустили.. Если он получил работу, он не будет запускать событиеng-click
, посколькуng-bind-html
не компилирует элемент для вас.. - person Pankaj Parkar   schedule 23.07.2015