KO Components Demo

Developer
Size
2,994 Kb
Views
8,096

How do I make an ko components demo?

Knockout components demo with the viewmodel written in Typescript. What is a ko components demo? How do you make a ko components demo? This script and codes were developed by Ruslan Marin on 07 December 2022, Wednesday.

KO Components Demo Previews

KO Components Demo - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>KO Components Demo</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <section id="templates"> <template id="myComponentTemplate"> <div class="first name">First name: <span data-bind="text:firstName"></span></div> <div class="last name">Last name: <span data-bind="text:lastName"></span></div> <div class="full name">Full name: <span data-bind="text:fullName"></span></div> </template>
</section>
<section> <mycomponent params="person: person1"></mycomponent> <mycomponent params="person: person2"></mycomponent>
</section> <script src='https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.0/knockout-min.js'></script> <script src="js/index.js"></script>
</body>
</html>

KO Components Demo - Script Codes CSS Codes

mycomponent:first-child { float: left;
}
mycomponent:last-child { float: right;
}
mycomponent .name { border-left: 5px solid lightblue; padding: 1em;
}
mycomponent .first { background: linear-gradient(to right, #f77, #7f7);
}
mycomponent .last { background: linear-gradient(to right, #77f, #7f7);
}
mycomponent .full { background: linear-gradient(to right, #77f, #f77);
}

KO Components Demo - Script Codes JS Codes

"use strict";
var Person = (function () { function Person(firstName, lastName) { this.firstName = ko.observable(); this.lastName = ko.observable(); this.firstName(firstName); this.lastName(lastName); } return Person;
}());
var MainViewModel = (function () { function MainViewModel() { this.person1 = new Person("John", "Doe"); this.person2 = new Person("John", "Smith"); } return MainViewModel;
}());
var MyComponentViewModel = (function () { function MyComponentViewModel(params) { var _this = this; this.firstName = params.person.firstName; this.lastName = params.person.lastName; this.fullName = ko.computed(function () { return _this.firstName() + " " + _this.lastName(); }); } return MyComponentViewModel;
}());
ko.components.register("mycomponent", { template: { element: "myComponentTemplate" }, viewModel: MyComponentViewModel
});
var mainVM = new MainViewModel();
ko.applyBindings(mainVM);
KO Components Demo - Script Codes
KO Components Demo - Script Codes
Home Page Home
Developer Ruslan Marin
Username marinru
Uploaded December 07, 2022
Rating 3
Size 2,994 Kb
Views 8,096
Do you need developer help for KO Components Demo?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Ruslan Marin (marinru) Script Codes
Create amazing Facebook ads with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!