16

Using Angular 4.3.0

Say I have a string like this that is a property of a component.

<p>test#2 bla bla</p><p>test1234 56</p><p>test test</p>

So, Im following along with the docs,
https://angular.io/guide/template-syntax#!#property-binding-or-interpolation-

This does not work:
What am I doing wrong?

<div class="panel-group">
    <div class="panel panel-default" *ngFor="let b of BlogPostList">
        <div class="panel-heading">{{b.Title}}</div>
        <div class="panel-body">
            <span style="text-align:left">Created:{{b.DateCreated | date: 'MM/dd/yyyy'}}</span><span style="text-align:right">Last updated{{b.DateUpdated | date: 'MM/dd/yyyy'}}</span>
            <br/>
            <div [innerHTML]="<b>test here</b>"></div>
        </div>
    </div>
</div>

error:

Unhandled Promise rejection: Template parse errors:
Parser Error: Unexpected token < at column 1 in [<b>test here</b>] in ...</span>
                <br/>
                <div [ERROR ->][innerHTML]="<b>test here</b>"></div>
            </div>
        </div>

3 Answers 3

25

You need to pass your [innerHTML] as a string wrap it with single quotes, <div [innerHTML]="'<b>test here</b>'"></div>

Sign up to request clarification or add additional context in comments.

3 Comments

I assigned the [innerHTML] like this [innerHTML]="'{blog.description}'" . This is giiving a error. - Template parse errors: Parser Error: Got interpolation ({{}}) where expression was expected at column 0 in
@YoYo, in your case it should be just [innerHTML]="blog.description}" give that a try.
<div [innerHTML] = "video_banner.LongDesc"></div>
4

You shoud write the parameter as a string.

 <div [innerHTML]="'test here'"></div>

Comments

1

Or if u want to use the parameter:

<div [innerHTML]="test.message"></div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.