AngularJS ng-csp directive

Definition and usage

ng-csp Directive is used to change AngularJS's security policy.

command is set ng-csp After the

command ng-csp The value of the no-unsafe-evalto prevent AngularJS from running any eval functions, but allow inline style injection.

command ng-csp The value of the no-inline-styleto prevent AngularJS from injecting any inline styles, but allow eval functions.

When developing applications for Google Chrome extensions or Windows applications, you need to use ng-csp Directive.

Note:ng-csp Instructions do not affect JavaScript, but they change the way AngularJS works, which means: you can still write eval functions, and they will execute as you expect, but AngularJS will not run its own eval function. It uses a compatibility mode that may slow down evaluation time by up to 30%.

Voorbeeld

Verander het gedrag van AngularJS ten opzichte van "eval" en inline styles:

<body ng-app="" ng-csp>
...

Probeer het zelf

Syntax

<element ng-csp="no-unsafe-eval | no-inline-style"></element>

Parameters

Parameters Beschrijving
  • no-unsafe-eval
  • no-inline-style

De waarde kan leeg zijn, wat betekent dat zowel eval als inline styles niet zijn toegestaan.

De waarde kan één van de twee beschreven waarden zijn.

De waarde kan twee waarden zijn, gescheiden door een puntkomma, maar dit heeft dezelfde betekenis als een lege waarde.