0

app.js is:

directive('test', ['name', function ($name) {

                            return {/// DDO
                                template:'<h1>'.$name.'<h1>',
                                link: function () {
                                    console.log($name);
                                }
                            };
                        }]).

While above name a service, which I am injecting into above directive. Above code works fine and data shows up both in console and web page.

BUT

error occurs when I replace template: $name with template: '<h1>'.$name.'</h1>'. The error I get is this:

Uncaught SyntaxError: Unexpected string

So if I can't concatenate string named $name like that with <h1> tags then how do I do it there inside the DDO?

Note: Above given code is definitely not complete code, it's just the part I had problem with. Also service named name was declared/defined/created(or whatever it's called) by using value function.

2 Answers 2

2

Concatenation in JS is done with the + symbol.

directive('test', ['name', function ($name) {
    return {/// DDO
        template:'<h1>' + $name + '<h1>',
        link: function () {
            console.log($name);
        }
    };
}])
Sign up to request clarification or add additional context in comments.

Comments

1

To concat string in javascript you have to use +

like this

'<h1>'+$name+'</h1>'

concat string by . is in php not in javascript

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.