Angularjs-读取更多自定义指令不适用于ng-bind-html指令

Mus*_* bw 7 html javascript angularjs

这些是我的自定义指令,用于读取更多和to_trusted(用于转换为html).

psp.directive('hmRead', function () {
    return {
        restrict:'AE',
        scope:{
            hmtext : '@',
            hmlimit : '@',
            hmfulltext:'@',
            hmMoreText:'@',
            hmLessText:'@',
            hmMoreClass:'@',
            hmLessClass:'@'
        },
        templateUrl: 'partials/common/read-more.html',
        controller : function($scope){
              $scope.toggleValue=function(){

                    if($scope.hmfulltext == true)
                        $scope.hmfulltext=false;
                    else if($scope.hmfulltext == false)
                        $scope.hmfulltext=true;
                    else
                        $scope.hmfulltext=true;
              }        
        }
    };
});

psp.filter('to_trusted', ['$sce', function($sce){
        return function(text) {
            return $sce.trustAsHtml(text);
        };
    }]);
Run Code Online (Sandbox Code Playgroud)

用html调用.

 <hm-read hmtext="{{data.content}}" ng-bind-html="data.content| to_trusted" hmlimit="100" hm-more-text="read more" hm-less-text="read less"></hm-read>
Run Code Online (Sandbox Code Playgroud)

如果iI删除ng-bind-html然后阅读更多工作正常但ng-bind-html指令readmore指令不起作用.

Moh*_*imi 0

作为阅读更多指令,您的指令的逻辑有点不清楚,特别是指令中templateUrl的使用、 hmfulltext 参数和ng-bind-html

顺便说一句,我在您的指令中通过假模板使用了您的指令:

template: '<p>template that is set in your directive</p>',
Run Code Online (Sandbox Code Playgroud)

和虚假内容范围变量如下:

$scope.data={};
$scope.data.content = '<p>template that passed into directive</p>';
Run Code Online (Sandbox Code Playgroud)

通过这个假模板,您的指令可以正常工作

在线执行

它表明问题出在“partials/common/read-more.html”模板或data.content范围变量中。你可以在这些地方寻找bug。