File tree Expand file tree Collapse file tree 5 files changed +20
-7
lines changed Expand file tree Collapse file tree 5 files changed +20
-7
lines changed Original file line number Diff line number Diff line change 1
1
var reang ;
2
2
reang = angular . module ( 'reang' , [ 'ngResource' ] )
3
+ . filter ( 'to_trusted' , [ '$sce' , function ( $sce ) {
4
+ return function ( text ) {
5
+ return $sce . trustAsHtml ( text ) ;
6
+ } ;
7
+ } ] )
3
8
. factory ( 'Posts' , function ( $resource ) {
4
9
return $resource ( ajaxInfo . json_url + 'posts/:id' , {
5
10
id : '@id'
Original file line number Diff line number Diff line change @@ -3,10 +3,11 @@ var $ = jQuery;
3
3
4
4
var Post = React . createClass ( {
5
5
render : function ( ) {
6
+ function post_content ( html ) { return { __html : html } }
6
7
return (
7
8
< article >
8
9
< h1 > { this . props . post . title } </ h1 >
9
- { this . props . post . content }
10
+ < div dangerouslySetInnerHTML = { { __html : this . props . post . content } } > </ div >
10
11
</ article >
11
12
)
12
13
}
@@ -22,14 +23,13 @@ var App = React.createClass({
22
23
dataType : 'json' ,
23
24
method : 'GET' ,
24
25
success : function ( res ) {
25
- console . log ( res ) ;
26
26
this . setState ( { data :res } )
27
27
} . bind ( this )
28
28
} ) ;
29
29
} ,
30
30
31
31
getInitialState : function ( ) {
32
- return { data : [ { title : 'test' } ] }
32
+ return { data : [ { title : 'test' , content : '<p>test</p>' } ] }
33
33
} ,
34
34
35
35
componentDidMount : function ( ) {
Original file line number Diff line number Diff line change @@ -7,6 +7,10 @@ var $ = jQuery;
7
7
var Post = React.createClass({
8
8
displayName: "Post",
9
9
render: function () {
10
+ var post_content = function (html) {
11
+ return { __html: html };
12
+ };
13
+
10
14
return React.createElement(
11
15
"article",
12
16
null,
@@ -15,7 +19,7 @@ var Post = React.createClass({
15
19
null,
16
20
this.props.post.title
17
21
),
18
- this.props.post.content
22
+ React.createElement("div", { dangerouslySetInnerHTML: { __html: this.props.post.content } })
19
23
);
20
24
}
21
25
});
@@ -32,14 +36,13 @@ var App = React.createClass({
32
36
dataType: "json",
33
37
method: "GET",
34
38
success: (function (res) {
35
- console.log(res);
36
39
this.setState({ data: res });
37
40
}).bind(this)
38
41
});
39
42
},
40
43
41
44
getInitialState: function () {
42
- return { data: [{ title: "test" }] };
45
+ return { data: [{ title: "test", content: "<p>test</p>" }] };
43
46
},
44
47
45
48
componentDidMount: function () {
Original file line number Diff line number Diff line change 1
1
var reang ;
2
2
reang = angular . module ( 'reang' , [ 'ngResource' ] )
3
+ . filter ( 'to_trusted' , [ '$sce' , function ( $sce ) {
4
+ return function ( text ) {
5
+ return $sce . trustAsHtml ( text ) ;
6
+ } ;
7
+ } ] )
3
8
. factory ( 'Posts' , function ( $resource ) {
4
9
return $resource ( ajaxInfo . json_url + 'posts/:id' , {
5
10
id : '@id'
Original file line number Diff line number Diff line change 6
6
Angular
7
7
<article ng-repeat="post in posts">
8
8
<h1>{{post.title}}</h1>
9
- {{ post.content}}
9
+ <div ng-bind-html=" post.content | to_trusted"></div>
10
10
</article>
11
11
</div>
12
12
<div class="col-sm-6">
You can’t perform that action at this time.
0 commit comments