2. Computed Observables

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type='text/javascript' src='knockout-3.4.0.js'></script>


</head>
<body>
The first name is <span data-bind="text: firstName"></span><br/>
The last name is <span data-bind="text: lastName"></span><br/>
The funll name is <span data-bind="text: fullName"></span><br/>

</body>
</html>
<script>
    function AppViewModel() {
        this.firstName = ko.observable('Bob');
        this.lastName = ko.observable('Smith');
        this.fullName = ko.pureComputed(function() {
            return this.firstName() + " " + this.lastName();
        }, this);
    }

    ko.applyBindings(AppViewModel());

</script>

Leave a Comment