0

I want to display the static content from js and also an image in it

content = {
    message: "The best city in the world?"
    answer:" Paris is one of the best city.'<img src ='assets/paris.gif alt="Smiley face" height="42" width="42">'".
}

My Html,

 ng-bind-html= content.answer

When i run my code,it says the error

Uncaught SyntaxError: Unexpected identifier

This is what i have tried.Can anyone find my error.Thanks.

1
  • 1
    Not quoting strings in JS, is that a new thing? Why don't you 'The best city in the world?' and the same in the other string? Next - read this Commented Jan 28, 2017 at 12:32

3 Answers 3

1

try this:

content = {
    message: 'The best city in the world?',
    answer: 'Paris is one of the best city.<img src ="assets/paris.gif" alt="Smiley face" height="42" width="42">.'
}
Sign up to request clarification or add additional context in comments.

1 Comment

Hi its my typo mistake when preparing question actually i did it before in my code.
0

Your content string doesn't have escape character. When you encapsulate a string with double quote then you can't use it again within the string unless it is with escape character \

content = {
    message: "The best city in the world?",
    answer: "Paris is one of the best city.'<img src =\"assets/paris.gif \" alt=\"Smiley face\" height=\"42\" width=\"42\">'"
}

And if you are using it in angular-template as you have HTML in your answer which you want to render, use it with ng-bind-html

3 Comments

Wha you are saying is ,i cant use the double quote again in a double quote?
You can use but with an escape character like this " name: \"kllp\" " or " name: 'kllp' "
OHH any how Thanks a lot.
0

There are some problems in your code. variable content should look like this:

var content = {
    message: "The best city in the world?",
    answer: 'Paris is one of the best city. <img src ="assets/paris.gif" alt="Smiley face" height="42" width="42">'
}

So please use double quotes inside the IMG tag, and single ones in the object property. Another problem is {{content.question}} means nothing, since you have only "message" and "answer" properties inside content. So you can use content.message

2 Comments

Hi its my typo mistake when preparing question actually i did it before in my code.
I think you do miss the comma after the message: "blablabla" line. That could cause a Uncaught syntaxerror: unexpected identifier error.

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.