Reputation: 2941
I am new to knockout. And I saw following code. I don't know what is difference between them. They both giving same result.
<p data-bind="text: FirstName"></p>
<p data-bind="text: FirstName()"></p>
//here FirstName comes from api response
Suppose api response is something like this
{"FirstName":"ABC"}
both of the upper p tag giving the same output
.
What is difference between that two?
Upvotes: 0
Views: 37
Reputation: 3589
To determine the text value programmatically, it is one of the techniques called
computed observables
So, when you use FirstName it will get the value. You can also get value by calling FirstName() and use it for any expression. For example, if the firstName is xyz then return Mr. xyz else return Ms. xyz.
FirstName() == 'xyz' ? 'Mr. xyz' : 'Ms. xyz'
Refer this for more details - http://knockoutjs.com/documentation/text-binding.html
Upvotes: 1