Javascript angular.js:$sanitize在$injector:moduler上失败,使用angular站点的确切代码示例

Javascript angular.js:$sanitize在$injector:moduler上失败,使用angular站点的确切代码示例,javascript,angularjs,Javascript,Angularjs,更新: 复制步骤: 访问此链接:.$sanitize 单击代码示例右上角的“编辑”按钮 选择JSFIDLE或plnkr 预期结果:将在“呈现”标题下看到html输出 我正在尝试实现html绑定。 奇怪的是,我无法使用此示例中的确切代码获得一个工作示例: .$消毒 它在有棱角的场地上工作,但在其他地方不起作用 我尝试过使用编辑链接plunk和JSFIDLE,但没有结果。 在本地运行时,我在控制台中遇到此错误: 以下是我在控制台中得到的信息: 未捕获错误:[$injector:moduler] HT

更新:

复制步骤:

  • 访问此链接:.$sanitize

  • 单击代码示例右上角的“编辑”按钮

  • 选择JSFIDLE或plnkr

  • 预期结果:将在“呈现”标题下看到html输出

    我正在尝试实现html绑定。 奇怪的是,我无法使用此示例中的确切代码获得一个工作示例:

    .$消毒

    它在有棱角的场地上工作,但在其他地方不起作用

    我尝试过使用编辑链接plunk和JSFIDLE,但没有结果。 在本地运行时,我在控制台中遇到此错误:

    以下是我在控制台中得到的信息:

    未捕获错误:[$injector:moduler]

    HTML:

    
    片段:
    指示
    怎么
    来源
    提供
    ng绑定html
    自动使用$sanitize
    div ng bind html=“snippet”
    /div ng绑定html 通过明确信任危险值绕过$sanitize div ng bind html=“深思熟虑地信任危险代码段() t/div ng绑定 自动逃逸 div ng bind=“snippet”
    /div
    JS:

    函数Ctrl($scope,$sce){
    $scope.snippet=
    “

    html\n”+ '单击此处\n'+ '片段

    '; $scope.delatelyTrustDangerousSnippet=function(){ 返回$sce.trustAsHtml($scope.snippet); }; }
    错误是不言自明的,您没有在fiddle或plunkr中包含angular.sanitize.js脚本

    我在下面添加了下面的脚本标记

    
    

    标题中是否同时包含angular.sanitize脚本以及是否将其注入应用程序中?我没有触摸代码。我使用了angular站点的工作代码示例,它在站点之外不工作。我正在用代码更新答案。我们能看看你的答案吗?或者提供一个jsfiddle@dcodesmith:我所拥有的正是提供的链接上的代码:。使用insert code函数将整个代码放入问题中是一个挑战。格式乱了套。你的页面上有
    吗?
    <!doctype html>
    <html ng-app="ngSanitize">
    <head>
    <script src="http://code.angularjs.org/1.2.10/angular.min.js"></script>
    <script src="script.js"></script>
       </head>
        <body>
        <div ng-controller="Ctrl">
            Snippet: <textarea ng-model="snippet" cols="60" rows="3"></textarea>
          <table>
            <tr>
              <td>Directive</td>
              <td>How</td>
              <td>Source</td>
              <td>Rendered</td>
            </tr>
            <tr id="bind-html-with-sanitize">
              <td>ng-bind-html</td>
              <td>Automatically uses $sanitize</td>
              <td><pre>&lt;div ng-bind-html="snippet"&gt;<br/>&lt;/div&gt;</pre></td>
              <td><div ng-bind-html="snippet"></div></td>
            </tr>
            <tr id="bind-html-with-trust">
              <td>ng-bind-html</td>
              <td>Bypass $sanitize by explicitly trusting the dangerous value</td>
              <td>
              <pre>&lt;div ng-bind-html="deliberatelyTrustDangerousSnippet()"&gt;
            t;/div&gt;</pre>
              </td>
              <td><div ng-bind-html="deliberatelyTrustDangerousSnippet()"></div></td>
             </tr>
             <tr id="bind-default">
              <td>ng-bind</td>
              <td>Automatically escapes</td>
              <td><pre>&lt;div ng-bind="snippet"&gt;<br/>&lt;/div&gt;</pre></td>
              <td><div ng-bind="snippet"></div></td>
            </tr>
          </table>
          </div>
      </body>
    </html>
    
    function Ctrl($scope, $sce) {
      $scope.snippet =
        '<p style="color:blue">an html\n' +
        '<em onmouseover="this.textContent=\'PWN3D!\'">click here</em>\n' +
        'snippet</p>';
      $scope.deliberatelyTrustDangerousSnippet = function() {
        return $sce.trustAsHtml($scope.snippet);
      };
    }
    
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.10/angular-sanitize.js"></script>