简体   繁体   English

无法绑定到“highlight”,因为它不是“code”的已知属性

[英]Can't bind to 'highlight' since it isn't a known property of 'code'

I am trying to use ngx-highlightjs and I have the following code in the module file.我正在尝试使用ngx-highlightjs ,并且模块文件中有以下代码。 I have multiple modules and so I am importing the HighlightModule, in the module in which the highlighting functionality is needed.我有多个模块,因此我在需要突出显示功能的模块中导入了 HighlightModule。 So the following code is not in App Module.所以下面的代码不在 App Module 中。

import { HighlightModule, HIGHLIGHT_OPTIONS, HighlightOptions} from 'ngx-highlightjs';

@NgModule({
  declarations: [
    EnvironmentComponent,
    RepositoryComponent
  ],
  imports: [
    CommonModule,
    SharedModule,
    HighlightModule
  ],
  providers: [
    EnvironmentService,
    AuthService,
    {
      provide: HIGHLIGHT_OPTIONS,
      useValue: {
        coreLibraryLoader: () => import('highlight.js/lib/core'),
        lineNumbersLoader: () => import('highlightjs-line-numbers.js'),
        languages: {
          typescript: () => import('highlight.js/lib/languages/typescript'),
          css: () => import('highlight.js/lib/languages/css'),
          xml: () => import('highlight.js/lib/languages/xml')
        }
      }
    }
  ],
})

and in the component template, I have the code like this:在组件模板中,我有这样的代码:

<pre><code [highlight]="fileData" (highlighted)="onHighlight($event)"></code></pre>

Now I am getting the following error and the output is not showing:现在我收到以下错误,并且 output 没有显示:

Can't bind to 'highlight' since it isn't a known property of 'code'

How can I fix this?我怎样才能解决这个问题?

I think problem is related to that angular doesn't see native javascript library which is highlight.js in this case.我认为问题与 angular 没有看到本机 javascript 库有关,在这种情况下是 highlight.js。 Because highlight attribute is directive defined by highlight.js因为 highlight 属性是由 highlight.js 定义的指令

I also had same problem.我也有同样的问题。 And fixed the issue by following these steps.并按照以下步骤解决了该问题。

1- I installed highlight.js manually in project directory. 1-我在项目目录中手动安装了 highlight.js。

npm install highlight.js

2- added following lines to scripts and styles parts in angular.json file. 2- 在 angular.json 文件中的脚本和 styles 部分中添加了以下行。

    "styles":[ 
     "./node_modules/highlight.js/styles/default.css"
     ],
    "scripts": [
     "./node_modules/highlight.js/lib/highlight.js"
    ]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法绑定到“控件”,因为它不是(myComponent)的已知属性 - Can't bind to 'control' since it isn't a known property of (myComponent) 无法绑定到“ useStickyClasses”,因为它不是“ div”的已知属性 - Can't bind to 'useStickyClasses' since it isn't a known property of 'div' Angular 7:无法绑定到“元素”,因为它不是 - Angular 7 : Can't bind to 'element' since it isn't a known property of 无法绑定到“matMenuTrigger”,因为它不是“a”的已知属性 - Can't bind to 'matMenuTrigger' since it isn't a known property of 'a' 无法绑定到“ngModel”,因为它不是“输入”的已知属性 - Can't bind to 'ngModel' since it isn't a known property of 'input' 无法绑定到“数据集”,因为它不是“画布”的已知属性 - Can't bind to 'datasets' since it isn't a known property of 'canvas' 无法绑定,因为它不是选择器组件的已知属性 - Can't bind to since it isn't a known property of selector component 无法绑定到“”,因为它不是“ angular 2”的已知属性 - can't bind to '' since it isn't a known property of '' angular 2 无法绑定到“appIfRoles”,因为它不是“p”的已知属性 - Can't bind to 'appIfRoles' since it isn't a known property of 'p' 无法绑定到“ chartType”,因为它不是“ canvas”的已知属性 - Can't bind to 'chartType' since it isn't a known property of 'canvas'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM