首页 > 解决方案 > 如何在 Angular 2+ 中显示 AngularJS

问题描述

我只想知道如何在 Angular 2+ 中显示 AngularJS(我有一个非常独特的情况需要这样做)

到目前为止,这是我尝试过的:

https://stackblitz.com/edit/angular-wbbzbz?file=src/app/app.component.ts

为了让您了解 stackblitz 上发生的事情:

我有一个基本的 html 字符串(我从这里得到:https://www.w3schools.com/angular/tryit.asp?filename=try_ng_default):

  myHtml = `
    <!DOCTYPE html>
    <html>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
    <body>

    <div ng-app="">

    <p>Input something in the input box:</p>
    <p>Name : <input type="text" ng-model="name" placeholder="Enter name here"></p>
    <h1>Hello {{name}}</h1>

    </div>

    </body>
    </html>
  `;

通过管道,我使用以下方法显示它:

<div [innerHTML]="myHtml | pipeSanitizeHtml"></div>

但我最终得到了这个(破碎的AngularJS):

在此处输入图像描述

标签: htmlangularjsangularinnerhtml

解决方案


如果您将其放在 Angular 2+index.html的标题中,AngularJS 将起作用:

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>

推荐阅读