从数据库编译动态HTML字符串
页指令
angular.module('myApp.directives')
    .directive('myPage', function ($compile) {
        return {
            templateUrl: 'page.html',
            restrict: 'E',
            compile: function compile(element, attrs, transclude) {
                // does nothing currently
                return {
                    pre: function preLink(scope, element, attrs, controller) {
                        // does nothing currently
                    },
                    post: function postLink(scope, element, attrs, controller) {
                        // does nothing currently
                    }
                }
            }
        };
    });页面指令模板
<div ng-controller="PageCtrl" > ... <!-- dynamic page content written into the div below --> <div ng-bind-html-unsafe="pageContent" > ...</div>
页控制器
angular.module('myApp')
  .controller('PageCtrl', function ($scope) {
        $scope.pageContent = '';
        $scope.$on( "receivedPageContent", function(event, args) {
            console.log( 'new page content received after DB call' );
            $scope.pageContent = args.htmlStrFromDB;
        });});拉风的咖菲猫
慕仙森