Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.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
Javascript 在Angular中本地安装MathJax_Javascript_Angular_Mathjax - Fatal编程技术网

Javascript 在Angular中本地安装MathJax

Javascript 在Angular中本地安装MathJax,javascript,angular,mathjax,Javascript,Angular,Mathjax,我遵循了帖子中提供的步骤 我已经设法让它工作了。我的问题是,我想将引用从cdn更改为本地安装的MathJax 我已经使用npm安装MathJax--save安装了MathJax 在我的angular.json文件中 最后,我尝试将myMathModule中对cdn的引用更改为以下内容,但它不起作用 还有HTML <div [appMath]="mathLatex"></div> 产生 如何使用已安装的MathJax 我当前尝试使用scr

我遵循了帖子中提供的步骤

我已经设法让它工作了。我的问题是,我想将引用从cdn更改为本地安装的
MathJax

  • 我已经使用
    npm安装MathJax--save安装了MathJax
  • 在我的angular.json文件中
  • 最后,我尝试将myMathModule中对cdn的引用更改为以下内容,但它不起作用
还有HTML

<div [appMath]="mathLatex"></div>

产生

如何使用已安装的MathJax

我当前尝试使用
script.src='/mathjax/es5/tex-mml-chtml.js?config=tex-mml-amchtml'在控制台中不生成错误,但不呈现方程式

@NgModule({
  declarations: [MathDirective],
  imports: [
    CommonModule
  ],
  exports: [MathDirective]
})
export class MathModule {
  constructor() {
    // see https://docs.mathjax.org/en/latest/advanced/dynamic.html
    const script = document.createElement('script') as HTMLScriptElement;
    script.type = 'text/javascript';
    script.src = '/mathjax/es5/tex-mml-chtml.js?config=TeX-MML-AM_CHTML';
    // script.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML';
    script.async = true;

    document.getElementsByTagName('head')[0].appendChild(script);

    const config = document.createElement('script') as HTMLScriptElement;
    config.type = 'text/x-mathjax-config';
    // register notifier to StartupHook and trigger .next() for all subscribers
    config.text = `
    MathJax.Hub.Config({
        skipStartupTypeset: true,
        tex2jax: { inlineMath: [["$", "$"]],displayMath:[["$$", "$$"]] }
      });
      MathJax.Hub.Register.StartupHook('End', () => {
        window.hubReady.next();
        window.hubReady.complete();
      });
    `;

    document.getElementsByTagName('head')[0].appendChild(config);
  }

  // this is needed so service constructor which will bind
  // notifier to window object before module constructor is called
  public static forRoot(): ModuleWithProviders<any> {
    return {
      ngModule: MathModule,
      providers: [{provide: MathService, useClass: MathService}]
    };
  }
}

  mathLatex: MathContent = {
    latex: 'When $a \\ne 0$, there are two solutions to $\\frac{5}{9}$'
  };
<div [appMath]="mathLatex"></div>