Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 使用prism highlighter的语法高亮显示不适用于动态数据库_Angularjs - Fatal编程技术网

Angularjs 使用prism highlighter的语法高亮显示不适用于动态数据库

Angularjs 使用prism highlighter的语法高亮显示不适用于动态数据库,angularjs,Angularjs,我在突出显示使用$http服务从数据库中获取的动态数据时遇到了问题。当数据在代码元素之间硬编码时,高亮显示工作正常,但当我尝试使用角度数据绑定{{singlepractice.code}显示动态数据时,它根本不工作。示例如下所示: myApp.directive('prism', [function() { return { restrict: 'A', link: function ($scope, element, attrs) { element.rea

我在突出显示使用$http服务从数据库中获取的动态数据时遇到了问题。当数据在代码元素之间硬编码时,高亮显示工作正常,但当我尝试使用角度数据绑定{{singlepractice.code}显示动态数据时,它根本不工作。示例如下所示:

 myApp.directive('prism', [function() {
 return {
    restrict: 'A',
    link: function ($scope, element, attrs) {
        element.ready(function() {
            Prism.highlightElement(element[0]);
        });
    }
   };
  }]
 );
HTML:

{{singlepractice.code}

在几乎所有情况下,当您将第三方插件与AngularJS一起使用时。当您要应用插件时,内容尚未编译

最快的解决方案是使用$timeout

myApp.directive('prism', function($timeout) {
  return {
    restrict: 'A',
    link: function (scope, element, attrs) {
       $timeout(function(){
          Prism.highlightElement(element[0]);
       }, 0);      
    }
  };
}
myApp.directive('prism', function($timeout) {
  return {
    restrict: 'A',
    link: function (scope, element, attrs) {
       $timeout(function(){
          Prism.highlightElement(element[0]);
       }, 0);      
    }
  };
}