Skip to content

Instantly share code, notes, and snippets.

@ozknozsrt
Created June 8, 2023 07:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ozknozsrt/7b9abd43f40fed591fc98bf63c048bb4 to your computer and use it in GitHub Desktop.
Save ozknozsrt/7b9abd43f40fed591fc98bf63c048bb4 to your computer and use it in GitHub Desktop.
knockout js ko component example
// wwwroot/js/ui-components klasörü açıp içinde her component'e özel dosyalar olabilir:
// alert-message.js
ko.components.register('alert-message', {
viewModel: function (params) {
var self = this;
self.css = params.css;
self.icon = params.icon;
self.text = params.text;
self.title = translate(`global.${self.icon}`);
},
template: `<div class="cs-alertbox" data-bind="css: css">
<i class="material-icons" data-bind="text: icon"></i>
<!-- ko if: title.length > 0 -->
<h4 data-bind="text: title"></h4>
<!-- /ko -->
<p data-bind="text: text"></p>
</div>`
});
// html üzerindeki kullanım şekli:
<alert-message params="css: 'cs-alertbox--warning-darker', icon: 'warning', text: translate('pages.graph.negativeValuesNotSupported')"></alert-message>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment