角ng-綁定-html及其內的指令柱塞連桿我有一個元素,我想將html綁定到它。<div ng-bind-html="details" upper></div>這很管用?,F在,除了它,我還有一個綁定到綁定html的指令:$scope.details = 'Success! <a href="#/details/12" upper>details</a>'但指令upper對DIV和錨不要進行評估。我該怎么做呢?
3 回答

慕哥6287543
TA貢獻1831條經驗 獲得超10個贊
HTML:
<div compile="details"></div>
聯(lián)署材料:
.directive('compile', ['$compile', function ($compile) { return function(scope, element, attrs) { scope.$watch( function(scope) { // watch the 'compile' expression for changes return scope.$eval(attrs.compile); }, function(value) { // when the 'compile' expression changes // assign it into the current DOM element.html(value); // compile the new DOM and link it to the current // scope. // NOTE: we only compile .childNodes so that // we don't get into infinite loop compiling ourselves $compile(element.contents())(scope); } ); };}])

慕姐4208626
TA貢獻1852條經驗 獲得超7個贊
angular.module('vkApp') .directive('compile', ['$compile', function ($compile) { return function(scope, element, attrs) { var ensureCompileRunsOnce = scope.$watch( function(scope) { // watch the 'compile' expression for changes return scope.$eval(attrs.compile); }, function(value) { // when the 'compile' expression changes // assign it into the current DOM element.html(value); // compile the new DOM and link it to the current // scope. // NOTE: we only compile .childNodes so that // we don't get into infinite loop compiling ourselves $compile(element.contents())(scope); // Use un-watch feature to ensure compilation happens only once. ensureCompileRunsOnce(); } ); };}]);
- 3 回答
- 0 關注
- 682 瀏覽
添加回答
舉報
0/150
提交
取消