Reputation: 565
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
.
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.
Upvotes: 0
Views: 2416
Reputation: 25352
To concat string in javascript
you have to use +
like this
'<h1>'+$name+'</h1>'
concat string by .
is in php
not in javascript
Upvotes: 1
Reputation: 1298
Concatenation in JS is done with the +
symbol.
directive('test', ['name', function ($name) {
return {/// DDO
template:'<h1>' + $name + '<h1>',
link: function () {
console.log($name);
}
};
}])
Upvotes: 2