2017-02-02 24 views
14

Khi tôi đã cố gắng để hiển thị dữ liệu của tôi như một văn bản html, nó hiển thị trong định dạng HTML nhưng khi tôi làm mới trang, tôi nhận được lỗi này:AngularJS: Cách giải quyết "Cố gắng sử dụng giá trị không an toàn trong bối cảnh an toàn"?

[$sce:unsafe] Attempting to use an unsafe value in a safe context.

Đây là AngularJS tôi mã:

data.attributes.task_name = $sce.trustAsHtml(data.attributes.task_name); 

HTML

<span ng-bind-html="taskdata.attributes.task_name" data-html="true" title="{{reminder.attributes.message}}"></span> 
+0

[answer] (http://stackoverflow.com/a/41997335/4927984) có giải quyết được sự cố của bạn không? – Mistalis

Trả lời

31

Từ 0.123.:

The value provided for use in a specific context was not found to be safe/trusted for use.

AngularJS's Strict Contextual Escaping (SCE) mode (enabled by default), requires bindings in certain contexts to result in a value that is trusted as safe for use in such a context. (e.g. loading an AngularJS template from a URL requires that the URL is one considered safe for loading resources.)

This helps prevent XSS and other security issues. Read more at Strict Contextual Escaping (SCE)

You may want to include the ngSanitize module to use the automatic sanitizing.


Bạn phải bao gồm ngSanitize:

tải nó trên index.html:

<script src="lib/angular/angular-sanitize.min.js"></script> 

Tiêm nó như là một sự phụ thuộc vào ứng dụng của bạn. js:

angular.module('myApp', ['...', 'ngSanitize']); 
+0

Điều này đã làm điều kỳ diệu cho phép tôi chia nhỏ một nhân vật với một dòng trong AngularJS. Cảm ơn bạn! – wickedchild

Các vấn đề liên quan