如下面这个例子,如果ng-bind-html中带有ng-model,需要加上这个指令进行实时编译,才能令ng-model生效
<div class="col-md-2" ng-bind-html="html" compile-template>
commonModule.directive('compileTemplate', ["$compile", "$parse", function ($compile, $parse) { return { link: function (scope, element, attr) { var parsed = $parse(attr.ngBindHtml); function getStringValue() { return (parsed(scope) || '').toString(); } scope.$watch(getStringValue, function () { $compile(element, null, -9999)(scope); // The -9999 makes it skip directives so that we do not recompile ourselves }); } } }]);