如何有条件地在 Angular 中包含脚本元素 [英] How to conditionally include script element in Angular

查看:24
本文介绍了如何有条件地在 Angular 中包含脚本元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试有条件地在我的页面上包含聊天内容:

I'm trying to conditionally include a chat on my page:

<body ng-app="myApp">
  <!-- some code -->

  <script type="text/javascript" ng-if="expression">
    window.$zopim||(function(d,s){var z=$zopim=function(c){z._.push(c)},$=z.s=
    d.createElement(s),e=d.getElementsByTagName(s)[0];z.set=function(o){z.set.
    _.push(o)};z._=[];z.set._=[];$.async=!0;$.setAttribute("charset","utf-8");
    $.src="//v2.zopim.com/?my-zopim-id";z.t=+new Date;$.
    type="text/javascript";e.parentNode.insertBefore($,e)})(document,"script");
  </script>
</body>

但似乎聊天脚本在 ng-if 指令之前执行.

but it seems that the chat script gets executed before ng-if directive.

如何让我的 Angular 应用程序先检查条件,然后从

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆