【问题标题】:Is it safe to use jQuery in _Layout.cshtml for a large Angular application?在 _Layout.cshtml 中为大型 Angular 应用程序使用 jQuery 是否安全?
【发布时间】:2015-05-09 07:10:15
【问题描述】:

我意识到这个问题有点宽泛,但我希望我能提供足够的上下文细节来缩小范围。在我非常陌生的项目中,我的任务之一是在用户单击注销链接时添加确认对话框。我已将链接更改如下,在_Layout.cshtml:

<div class="row inner">
    @if (Request.IsAuthenticated)
    {
        using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { @id = "logoutForm", @class = "col-md-8 col-md-offset-2 rightText" }))
        {
            @Html.AntiForgeryToken()
            <a href="@Url.Action("CreateNewMlamApplication", "MlamApplication")"><img src="/img/icons/plusIcon.png" class="icon" /></a>
            <a href="@Url.Action("Index", "Home")"><img src="/img/icons/documentIcon.png" class="icon" /></a>
            @* BKMOD <a href="javascript:document.getElementById('logoutForm').submit()"><img src="/img/icons/gearIcon.png" class="icon" /></a>*@
            <a class="logout-link-confirm" href="#" ><img src="/img/icons/gearIcon.png" class="icon" /></a>
        }
    }
</div>

然后,我将一个处理程序连接到布局底部的logout-link-confirm

    <script>
        $(function() {
            $(".logout-link-confirm").click(function() {
                $('#modalLogoutConfirmation').modal('show');
            });
            $(".logout-link-final").click(function () {
                $('#logoutForm').submit()
            });
        });
    </script>
    @RenderSection("scripts", required: false)
</body>

modalLogoutConfirmation 弹出窗口中,当用户确认他们的选择时,我执行实际注销:$('#logoutForm').submit()

这与 angular 没有直接关系,因为 angular 仅在此布局中的某些 body 视图中起作用,但它已加载,我有点担心我的 jQuery 可能引入的任何副作用。

【问题讨论】:

  • 你为什么不使用 modal "directive from angular Ui team 而不是 Jquery?
  • @sani,因为注销按钮和模式超出了“环境”角度应用程序的范围,我宁愿不引入第二个应用程序或干预主应用程序的范围。跨度>

标签: jquery asp.net-mvc angularjs


【解决方案1】:

是的,它是安全的。我假设模态本身不涉及任何 Angular 逻辑。即使有,您也必须有意尝试干扰 Angular 以使任何副作用发生。

【讨论】:

  • 谢谢。我对 Angular 的信心在学习这样的东西方面呈指数级增长。
猜你喜欢
  • 2019-01-28
  • 1970-01-01
  • 1970-01-01
  • 2014-07-28
  • 1970-01-01
  • 2018-05-03
  • 1970-01-01
  • 2020-05-10
  • 1970-01-01
相关资源
最近更新 更多