如何处理在 AngularJS 中禁用 JavaScript [英] How to handle JavaScript being disabled in AngularJS

查看:27
本文介绍了如何处理在 AngularJS 中禁用 JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AngularJS 依赖于启用的 JavaScript.这意味着如果有人访问用 AngularJS 构建的应用程序或网站,它将无法正确呈现.

在使用 AngularJS 时,用于处理禁用 JavaScript 的访问者的常用约定是什么?

请解释为什么会这样?

问题包括处理 Angular JS 指令和 {{data_bindings}} 的情况.使页面无法呈现页面时数据不显示.

解决方案

在考虑了关于这个问题的其他答案和如何检测 JavaScript 是否被禁用?" 以及对 AngularJS 的一些进一步研究.

首先,您需要隐藏通过数据绑定显示的所有变量.

这可以使用附加到 HTML 的 ng-cloak 来完成标签.

<!-- 页面内容在这里-->{{bound_data}}

它还包含一个用于隐藏该元素的 CSS 标记.

[ng:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], .ng-cloak, .x-ng-cloak {显示:无!重要;}

然后,您将希望在用户阻止或禁用 JavaScript 时显示替代内容.这是使用标签完成的.

您可以选择创建功能较少的应用,或者要求访问者启用 JavaScript 才能使用您的应用.

AngularJS is dependent upon JavaScript being enabled. This means that if someone visits an application or website built in AngularJS it will not render properly.

What are common conventions used to handle visitors with JavaScript disabled when using AngularJS?

Please explain why this is the case?

Included in the problem is the case of handling angular JS directives and {{data_bindings}}. So that the data does not show when the page cannot render the page.

解决方案

After considering other answers on this question and "How to detect if JavaScript is disabled?" as well as some further research on AngularJS.

First off you will want to hide all variables displayed through the databindings.

This can be done using ng-cloak which is appended to an HTML tag.

<div ng-cloak>
    <!-- page content here -->
    {{bound_data}}
</div>

It also includes a CSS tag to hide that element.

[ng:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], .ng-cloak, .x-ng-cloak {
    display: none !important;
}

You will then want alternate content to be displayed for when a user has JavaScript blocked or disabled. This is done using the tag.

<noscript>
    You must have JavaScript enabled to use this app.
</noscript>

You have the choice to create an app with reduced features and functionality or require the visitor to have JavaScript enabled in order to use your app at all.

这篇关于如何处理在 AngularJS 中禁用 JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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