Tim Tom
Tim Tom

Reputation: 2162

How do I write this expression in knockout.js?

It is simple to write data-bind expression like:

<span data-bind="text: userName"></span>

But I want to include Hello before userName so the span should look like:

Hello World

where World is userName

How can I write this in data binding expression?

Note: Please do not suggest that I move Hello out of span and write it statically :)

Upvotes: 0

Views: 113

Answers (1)

SLaks
SLaks

Reputation: 887215

Knockout can bind expressions too:

<span data-bind="text: 'hello ' + userName()"></span>

Upvotes: 1

Related Questions