Thursday, October 11, 2018

OJET8: How to create OJet Project

OJET8: How to create OJet Project

Step1:

Install NodeJS -> https://nodejs.org/en/  -> Download

Note: OJET project will not run on NodeJS server, we just use the NodeJS-NPM capabilities for installations

verify NodeJS installation
-------------------------
In command prompt ->
node --version
npm --version




Step2:
In command prompt ->
npm install -g @oracle/ojet-cli

Note : If proxy issue comes then only do below commands

npm config rm proxy

npm config set strict-ssl false

npm config set registry "http://registry.npmjs.org/"

npm config set proxy "http://www-proxy.us.oracle.com:80"

npm config set https-proxy "http://www-proxy.us.oracle.com:80"

verify OJET installation
-------------------------
ojet --version



####################################################################################

2 ways we can create OJET Project
--------------------------------------------
1> Through command line -> open command prompt -> cd to any folder -> give command line as "ojet create FirstApp --template=navbar"

2> Netbean IDE -> File -> New Project -> in "HTML5/Javascript" -> Select "Oracle JET Base Distribution" -> give Project Name "MyFirstOJETProject" -> Finish

####################################################################################

We will see Through command line
---------------------------------------------

ojet create FirstApp --template=navbar
For more commands - https://www.oracle.com/webfolder/technetwork/jet/globalGetStarted.html

cd FirstApp

ojet build

ojet serve











We will add new Tab and build and run again







OJET7: OJET Bindings

OJET7: OJET Bindings

2 types of Binding OJET supports
-------------------------------------------

  • KO binding
  • OJET custom binding


KO binding
-------------
Checkbox - <input type="checkbox" data-bind="checked: agreed">
Button - <button data-bind="enable:agreed">
Text - <input type="text" data-bind="value:newStudent, valueUpdate:'afterkeydown'"/>
Button - <button data-bind="click: addStudent, enable:newStudent().length > 0">
select - <select multiple data-bind="options:studentList, selectedOptions:selectedStd">
ForEach - <p> & <table>
------------------------
<p data-bind="foreach: studentList"><input name="std" type="radio" data-bind="value: $data, checked: $parent.choosenRadioStd"/></p>

<table data-bind="foreach:personList"
<td><span data-bind="text: $data.firstName">

 <!-- ko foreach:personList -->
    <span data-bind="text: $data.firstName"></span>
 <!-- /ko -->


OJET custom binding
---------------------
{{value}} - 2 way binding

[[value]] - 1 way binding

Examples:
-------------
<oj-input-text value="{{uname}}" required></oj-input-text>
<span> <oj-bind-text value="[[uname]]"></oj-bind-text>   </span>
<oj-input-date value="{{dob}}" required></oj-input-date>
<oj-button on-oj-action='[[buttonClick]]' id="mybutton"> Click Me</oj-button>
<oj-checkboxset id="checkboxSetAgreeId" labelled-by="agreeId"
                            value="{{agreement}}"
                            required >
              <oj-option id="agree" value="agree">I Agree</oj-option>
            </oj-checkboxset>
<oj-radioset id="radiosetBasicDemoId" labelled-by="mainlabelid"
                       value="{{currentColor}}" >
            <oj-option id="blueopt" value="blue">Blue</oj-option>
            <oj-option id="greenopt" value="green">Green</oj-option>
            <oj-option id="redopt" value="red">Red</oj-option>
          </oj-radioset>


####################Example1############################
first.html
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<title>OJET Page</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="js/libs/require/require.js" data-main="js/first"></script>
<link rel="stylesheet" id="css" href="css/libs/oj/v5.2.0/alta/oj-alta-min.css">
</head>
<body>
<div>Hi.. <h1 data-bind="text:uname"></h1></div>
<p>
Good Morning123,
<span> <oj-bind-text value="[[uname]]"></oj-bind-text> </span>
</p>
<oj-button on-oj-action='[[buttonClick]]' id="mybutton"> Click Me</oj-button>
<oj-file-picker accept='[[acceptValue]]' on-oj-select='[[fileSelected]]'></oj-file-picker>
<p>Selected file is : <span data-bind="text:fileName"></span></p>
<oj-toolbar>
<oj-button>Home</oj-button>
<oj-button>Customers</oj-button>
<oj-button>Contact Us</oj-button>
</oj-toolbar>
</body>
</html>

js/first.js

/**
* Example of Require.js boostrap javascript
*/

requirejs.config({
// Path mappings for the logical module names
paths: {
'knockout': 'libs/knockout/knockout-3.4.2',
'jquery': 'libs/jquery/jquery-3.3.1.min',
'jqueryui-amd': 'libs/jquery/jqueryui-amd-1.12.1.min',
'ojs': 'libs/oj/v5.2.0/min',
'ojL10n': 'libs/oj/v5.2.0/ojL10n',
'ojtranslations': 'libs/oj/v5.2.0/resources',
'text': 'libs/require/text',
'promise': 'libs/es6-promise/es6-promise.min',
'hammerjs': 'libs/hammer/hammer-2.0.8.min',
'signals': 'libs/js-signals/signals.min',
'ojdnd': 'libs/dnd-polyfill/dnd-polyfill-1.0.0.min',
'css': 'libs/require-css/css.min',
'customElements': 'libs/webcomponents/custom-elements.min',
'proj4': 'libs/proj4js/dist/proj4'
},
// Shim configurations for modules that do not expose AMD
shim: {
'jquery': {
exports: ['jQuery', '$']
}
},
// This section configures the i18n plugin. It is merging the Oracle JET built-in translation
// resources with a custom translation file.
// Any resource file added, must be placed under a directory named "nls". You can use a path mapping or you can define
// a path that is relative to the location of this main.js file.
config: {
ojL10n: {
merge: {
//'ojtranslations/nls/ojtranslations': 'resources/nls/myTranslations'
}
},
text: {
// Override for the requirejs text plugin XHR call for loading text resources on CORS configured servers
useXhr: function (url, protocol, hostname, port) {
// Override function for determining if XHR should be used.
// url: the URL being requested
// protocol: protocol of page text.js is running on
// hostname: hostname of page text.js is running on
// port: port of page text.js is running on
// Use protocol, hostname, and port to compare against the url being requested.
// Return true or false. true means "use xhr", false means "fetch the .js version of this resource".
return true;
}
}
}
});
/**
* A top-level require call executed by the Application.
* Although 'ojcore' and 'knockout' would be loaded in any case (they are specified as dependencies
* by the modules themselves), we are listing them explicitly to get the references to the 'oj' and 'ko'
* objects in the callback.
*
* For a listing of which JET component modules are required for each component, see the specific component
* demo pages in the JET cookbook.
*/
require(['ojs/ojcore', 'knockout', 'jquery', 'ojs/ojknockout','ojs/ojbutton', 'ojs/ojfilepicker','ojs/ojtoolbar'], // add additional JET component modules as needed
function(oj, ko, $) // this callback gets executed when all required modules are loaded
{
// add any startup code that you want here
function MyModel(){
var self = this;
console.log("Model created..")
self.uname = ko.observable("Pavan..");
self.buttonClick = function(event){
console.log("Inside buttonClick - ",event);
console.log("button id - ",event.target.id);
}
self.fileName = ko.observable();
self.fileSelected = function(event){
console.log("Inside fileSelected - ",event);
console.log("button id - ",event.detail.files[0]);
self.fileName(event.detail.files[0].name);
}
self.acceptValue = ko.observableArray(['image/*']);
}
$(document).ready(function(){
ko.applyBindings(new MyModel());
});
}
);

####################Example 2############################
formElements.html

<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html lang="fr">
<head>
<title>OJET Page</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="js/libs/require/require.js" data-main="js/formElements"></script>
<link rel="stylesheet" id="css" href="css/libs/oj/v5.2.0/alta/oj-alta-min.css">
</head>
<body>
<h2>Sample Form</h2>
<div>
<oj-label show-required>UserName</oj-label>
<oj-input-text value="{{uname}}" required></oj-input-text>
<oj-label show-required>Password</oj-label>
<oj-input-password value="{{pwd}}" required></oj-input-password>
<oj-label show-required>DOB</oj-label>
<oj-input-date value="{{dob}}" required></oj-input-date>
<oj-label id="agreeId" show-required>License Agreement </oj-label>
<oj-checkboxset id="checkboxSetAgreeId" labelled-by="agreeId"
value="{{agreement}}"
required >
<oj-option id="agree" value="agree">I Agree</oj-option>
</oj-checkboxset>
<oj-label id="mainlabelid">Colors</oj-label>
<oj-radioset id="radiosetBasicDemoId" labelled-by="mainlabelid"
value="{{currentColor}}" >
<oj-option id="blueopt" value="blue">Blue</oj-option>
<oj-option id="greenopt" value="green">Green</oj-option>
<oj-option id="redopt" value="red">Red</oj-option>
<oj-option id="limeopt" value="lime">Lime</oj-option>
<oj-option id="aquaopt" value="aqua">Aqua</oj-option>
</oj-radioset>
</div>
<oj-label show-required>Address</oj-label>
<oj-input-text value="{{address}}" disabled></oj-input-text>
<div>
<p>You entered below Username : <span data-bind="text: uname"></span></p>
<p>You entered below Password : <span data-bind="text: pwd"></span></p>
<p>You entered below DOB : <span data-bind="text: dob"></span></p>
<p>License Agreement : <span data-bind="text: agreement"></span></p>
<p>License Agreement : <span data-bind="text: currentColor"></span></p>
</div>
</body>
</html>

formElements.js

/**
* Example of Require.js boostrap javascript
*/

requirejs.config({
// Path mappings for the logical module names
paths: {
'knockout': 'libs/knockout/knockout-3.4.2',
'jquery': 'libs/jquery/jquery-3.3.1.min',
'jqueryui-amd': 'libs/jquery/jqueryui-amd-1.12.1.min',
'ojs': 'libs/oj/v5.2.0/min',
'ojL10n': 'libs/oj/v5.2.0/ojL10n',
'ojtranslations': 'libs/oj/v5.2.0/resources',
'text': 'libs/require/text',
'promise': 'libs/es6-promise/es6-promise.min',
'hammerjs': 'libs/hammer/hammer-2.0.8.min',
'signals': 'libs/js-signals/signals.min',
'ojdnd': 'libs/dnd-polyfill/dnd-polyfill-1.0.0.min',
'css': 'libs/require-css/css.min',
'customElements': 'libs/webcomponents/custom-elements.min',
'proj4': 'libs/proj4js/dist/proj4'
},
// Shim configurations for modules that do not expose AMD
shim: {
'jquery': {
exports: ['jQuery', '$']
}
},
// This section configures the i18n plugin. It is merging the Oracle JET built-in translation
// resources with a custom translation file.
// Any resource file added, must be placed under a directory named "nls". You can use a path mapping or you can define
// a path that is relative to the location of this main.js file.
config: {
ojL10n: {
merge: {
//'ojtranslations/nls/ojtranslations': 'resources/nls/myTranslations'
}
},
text: {
// Override for the requirejs text plugin XHR call for loading text resources on CORS configured servers
useXhr: function (url, protocol, hostname, port) {
// Override function for determining if XHR should be used.
// url: the URL being requested
// protocol: protocol of page text.js is running on
// hostname: hostname of page text.js is running on
// port: port of page text.js is running on
// Use protocol, hostname, and port to compare against the url being requested.
// Return true or false. true means "use xhr", false means "fetch the .js version of this resource".
return true;
}
}
}
});
/**
* A top-level require call executed by the Application.
* Although 'ojcore' and 'knockout' would be loaded in any case (they are specified as dependencies
* by the modules themselves), we are listing them explicitly to get the references to the 'oj' and 'ko'
* objects in the callback.
*
* For a listing of which JET component modules are required for each component, see the specific component
* demo pages in the JET cookbook.
*/
require(['ojs/ojcore', 'knockout', 'jquery', 'ojs/ojknockout','ojs/ojbutton', 'ojs/ojfilepicker','ojs/ojtoolbar','ojs/ojlabel','ojs/ojinputtext','ojs/ojdatetimepicker', 'ojs/ojcheckboxset','ojs/ojradioset'], // add additional JET component modules as needed
function(oj, ko, $) // this callback gets executed when all required modules are loaded
{
// add any startup code that you want here
function MyModel(){
var self = this;
console.log("Model created..")
self.uname = ko.observable("Pavan..");
self.pwd = ko.observable();
self.dob = ko.observable();
self.agreement = ko.observable();
self.currentColor = ko.observable('red');
self.address = ko.observable("You cannot change..Disabled.");
}
$(document).ready(function(){
ko.applyBindings(new MyModel());
});
}
);



OJET6: KnockoutJS Code

OJET6: KnockoutJS Code 



  • KnockoutJS1_Introduction
  • KnockoutJS2_1_Bindings_On_BasicComponents
  • KnockoutJS2_BasicBinding_&_Observable_&_Subscribe
  • KnockoutJS3_checkbox_button_select_radio
  • KnockoutJS4_1_Apply_2_Bindings
  • KnockoutJS4_2_data-bind_html
  • KnockoutJS4_foreach_1.data-bind_&_ko foreach
  • KnockoutJS5_Template_Create_&_Use
  • KnockoutJS6_CustomComponen_uses_Template

###########################################################################
  • KnockoutJS2_1_Bindings_On_BasicComponents

////////////////////////////////////////////////////////////////////////////////////////////////////////////////



Checkbox - <input type="checkbox" data-bind="checked: agreed">
Button - <button data-bind="enable:agreed">
Text - <input type="text" data-bind="value:newStudent, valueUpdate:'afterkeydown'"/>
Button - <button data-bind="click: addStudent, enable:newStudent().length > 0">
select - <select multiple data-bind="options:studentList, selectedOptions:selectedStd">

////////////////////////////////////////////////////////

ForEach - <p> & <table>
<p data-bind="foreach: studentList">>
              <input name="std" type="radio" data-bind="value: $data, checked: $parent.choosenRadioStd"/>
            </p>

<table data-bind="foreach:personList"
<td><span data-bind="text: $data.firstName">

 <!-- ko foreach:personList -->
    <span data-bind="text: $data.firstName"></span>
 <!-- /ko -->

////////////////////////////////////////////////////////

Template
----------
1. Create template -  <script type="text/html" id="personTeamplate">
2. use it using - <div data-bind="template:   
data
foreach

////////////////////////////////////////////////////////

Component
----------
1. register component with - ViewModel and template
2. Use it using - data-bind="component:
with param
without param
direct tag

###########################################################################
  • KnockoutJS2_BasicBinding_&_Observable_&_Subscribe
<!DOCTYPE html>
<head>
<script src = "https://ajax.aspnetcdn.com/ajax/knockout/knockout-3.1.0.js"
type = "text/javascript"></script>
</head>
<body>
<!-- This is called "view" of HTML markup that defines the appearance of UI -->

<p>Enter your name: <input data-bind = "value: yourName" /></p>
<p>Hi <strong data-bind = "text: yourName"></strong> Good Morning!!!</p>

<p>Enter your age: <input type="text" data-bind="value: yourAge" /></p>
<p>Your age : <span data-bind="text: yourAge"></span></p>

<p>In 2020, your age is : <span data-bind = "text:newComputedAge"></span></p>

<div>Languages : <p data-bind="text : dataArray"></p></div>
<script>
// <!-- This is called "viewmodel". This javascript section defines the data and behavior of UI -->
function AppViewModel() {

///////////////////////////////////////////////////////////////////////////////

this.yourName = ko.observable(""); //marking our variable as Observable
this.yourName.subscribe(function(val){ //since our variable is Observable , now we can subscirbe on that
console.log("New Name:", val);
});

///////////////////////////////////////////////////////////////////////////////
//this.yourAge = 20;
this.yourAge = ko.observable(20); //marking our variable as Observable
this.yourAge.subscribe((val) =>{ //since our variable is Observable , now we can subscirbe on that
console.log("New Age:", val)
if(val > 100){
this.yourAge(20);
}
});


///////////////////////////////////////////////////////////////////////////////
//or i can give it inside above subscribe only, but this has to obserable to get it reflect in UI
this.newComputedAge = ko.computed(() => {
return parseInt(this.yourAge()) + 2;
});

//this.dataArray = ['C','C++','JAVA'];
this.dataArray = ko.observableArray(['C','C++','JAVA']);

}

vm = new AppViewModel();
// Activates knockout.js
ko.applyBindings(vm );

setTimeout(function(){vm.yourName("Abhijit")}, 2000);
setTimeout(function(){vm.dataArray.push('Javascript');}, 2000);

</script>
</body>
</html>
###########################################################################
  • KnockoutJS3_checkbox_button_select_radio

<!DOCTYPE html>
<html>
<head>
<title>Knockout - Model Binding</title>
<script src = 'scripts/jquery-3.1.1.min.js'></script>
<script src = 'scripts/knockout-3.4.1.js'></script>
<script>
$(document).ready(function(){
function MyModel(){
this.agreed = ko.observable(false);
this.newStudent= ko.observable("");
this.studentList = ko.observableArray();
self = this;

this.addStudent = function(){
self.studentList.push(self.newStudent());
}

this.selectedStd = ko.observableArray();

this.removeStudent = function(){
selection = self.selectedStd();
for(i=0; i< selection.length ; i++){
self.studentList.remove(selection[i]);
}

}

this.choosenRadioStd = ko.observable();

}
ko.applyBindings(new MyModel());
})
</script>
</head>
<body>

<p>Here is License agreement text</p>
<!-- Checkbox Test -->
<p>Accept License <input type="checkbox" data-bind="checked: agreed"></p>
<p data-bind="text:agreed"></p>

<!-- Visible/Enable Test -->
<!-- <button data-bind="visible:agreed">Download</button> -->
<button data-bind="enable:agreed">Download</button>

<hr>

<div>Enter Student Name:
<input type="text" data-bind="value:newStudent, valueUpdate:'afterkeydown'"/>
<button data-bind="click: addStudent, enable:newStudent().length > 0">Add</button>
</div>

<p>Here are the student list :
<!-- <span data-bind="text: studentList"></span> -->
<select multiple data-bind="options:studentList, selectedOptions:selectedStd"></select>
Selected student :
<span data-bind="text:selectedStd"></span>

<button data-bind="enable:selectedStd().length > 0, click:removeStudent">Remove Item</button>

</p>
<hr>
<div>Choose any student:
<p data-bind="foreach: studentList">
<label data-bind="text:$data"></label>
<input name="std" type="radio" data-bind="value: $data, checked: $parent.choosenRadioStd"/>
</p>

<p>Choosen Radio student is : <span data-bind="text:choosenRadioStd"></span></p>

</div>
</body>
</html>
###########################################################################
  • KnockoutJS4_1_Apply_2_Bindings


<!DOCTYPE html>
<html>
<head>
<title>Knockout - Model Binding</title>
<script src = 'scripts/jquery-3.1.1.min.js'></script>
<script src = 'scripts/knockout-3.4.1.js'></script>
<script>
$(document).ready(function(){
var firstRankHolder = {
firstName: ko.observable(),
lastName: ko.observable()
};
var secondRankHolder = {
fName: 'Sidney',
lName: 'Sheldon',
score: 1200,
address:'Bangalore'
};

var dummySecondRankHolder = {
firstName: secondRankHolder.fName,
lastName: secondRankHolder.lName,
fullName: secondRankHolder.fName + ' ' + secondRankHolder.lName
}

ko.applyBindings(firstRankHolder, document.getElementById('firstRankDiv'));
ko.applyBindings(dummySecondRankHolder, document.getElementById('secondRankDiv'));
})
</script>
</head>
<body>

<div id="firstRankDiv">
<h2>First Rank</h2>
First Name : <input type="text" data-bind="value:firstName, valueUpdate:'keypress'"><br/>
Second Name : <input type="text" data-bind="value:lastName"><br/>

Span First Name : <span data-bind="text:firstName"></span>
Span Last Name : <span data-bind="text:lastName"></span>
</div>

<div id="secondRankDiv">
<h2>Second Rank</h2>
First Name : <input type="text" data-bind="value:firstName"><br/>
Second Name : <input type="text" data-bind="value:lastName"> <br/>
Score : <input type="text" data-bind="value:fullName">
</div>
</body>
</html>

###########################################################################
  • KnockoutJS4_2_data-bind_html

<!DOCTYPE html>
<html>
<head>
<title>Knockout - Bindings</title>
<script src = 'scripts/jquery-3.1.1.min.js'></script>
<script src = 'scripts/knockout-3.4.1.js'></script>
<script type="text/javascript">
    $(document).ready(function(){
       var viewModel = {
        details: ko.observable()
       };
        viewModel.details("<em>For further details, view the report <a href='http://google.com'>here</a>.</em>");
         ko.applyBindings(viewModel);
    })  
  </script>
</head>
<body>
       <div data-bind="text: details"></div>

       <br>
       <br>

       <div data-bind="html: details"></div>
</body>
</html>




###########################################################################
  • KnockoutJS4_foreach_1.data-bind_&_ko foreach

<!DOCTYPE html>
<html>
<head>
<title>Knockout - Model Binding</title>
<script src = 'scripts/jquery-3.1.1.min.js'></script>
<script src = 'scripts/knockout-3.4.1.js'></script>
<script>
$(document).ready(function(){
function MyModel(){
this.personList = [
{
firstName: "John",
lastName:"smith"
},
{
firstName: "Merry",
lastName:"Rose"
}
]

}



ko.applyBindings(new MyModel());
})
</script>
</head>
<body>

<p>Here is Student List</p>
<table data-bind="foreach:personList" border="1">
<th>
<td>FristName</td>
<td>LastName</span></td>
</th>
<tr>
<td><span data-bind="text: $data.firstName"></span></td>
<td><span data-bind="text: $data.lastName"></span></td>
</tr>

</table>

<p>List of People:
<br>
<!-- ko foreach:personList -->
<span data-bind="text: $data.firstName"></span>
<!-- /ko -->
</p>

</body>
</html>


###########################################################################

  • KnockoutJS5_Template_Create_&_Use

<!DOCTYPE html>
<html>
<head>
<title>Knockout - Model Binding</title>
<script src = 'scripts/jquery-3.1.1.min.js'></script>
<script src = 'scripts/knockout-3.4.1.js'></script>
<script>
$(document).ready(function(){
function MyModel(){
this.personList = [
{
firstName: "John",
lastName:"smith",
mobile:1234
},
{
firstName: "Merry",
lastName:"Rose",
mobile:7890
}
]

}



ko.applyBindings(new MyModel());
})
</script>
</head>
<body>

<p>Template binding example</p>
<!-- Using Teamplate -->
<div>List of people:
<!-- <div data-bind="template: {name: 'personTeamplate', data:personList[0]}"></div> -->
<div data-bind="template: {name: 'personTeamplate', foreach:personList}"></div>
</div>

<!-- Create teamplate, since its a repetative DOM element -->
<script type="text/html" id="personTeamplate">
<h3>FirstName : <span data-bind="text:firstName"></span></h3>
<h4>LastName : <span data-bind="text:lastName"></span></h4>
<h4>Mobile : <em data-bind="text:mobile"></em></h4>
</script>

</body>
</html>

2nd example:

<!DOCTYPE html>
<head>
<title>KnockoutJS Templating - Named Template</title>
<script src = "https://ajax.aspnetcdn.com/ajax/knockout/knockout-3.3.0.js"
type = "text/javascript"></script>
</head>

<body>
<h2>Friends List</h2>
Here are the Friends from your contact page:
<div data-bind = "template: { name: 'friend-template', data: friend1 }"></div>
<div data-bind = "template: { name: 'friend-template', data: friend2 }"></div>

<script type = "text/html" id = "friend-template">
<h3 data-bind = "text: name"></h3>
<p>Contact Number: <span data-bind = "text: contactNumber"></span></p>
<p>Email-id: <span data-bind = "text: email"></span></p>
</script>

<script type = "text/javascript">
function MyViewModel() {
this.friend1 = {
name: 'Smith',
contactNumber: 4556750345,
email: 'smith123@gmail.com'
};
this.friend2 = {
name: 'Jack',
contactNumber: 6789358001,
email: 'jack123@yahoo.com'
};
}

var vm = new MyViewModel();
ko.applyBindings(vm);
</script>
</body>
</html>
###########################################################################
  • KnockoutJS6_CustomComponen_uses_Template

<!DOCTYPE html>
<html>
<head>
<title>Knockout - Model Binding</title>
<script src = 'scripts/jquery-3.1.1.min.js'></script>
<script src = 'scripts/knockout-3.4.1.js'></script>
<script>
$(document).ready(function(){
//Create Our own component - http-error
ko.components.register('http-error',
{
viewModel:function(params){
this.message = params && params.msg || 'Unkown error';
this.httpCode = params && params.code || 505;
},
template: {element : 'httpTemplate'}
});

ko.applyBindings();
})
</script>

<!-- Create Template -->
<script type="text/html" id="httpTemplate">
<h2>Http Error: <p data-bind="text:message, style:{color: httpCode < 500 ? 'red' : 'cyan'}"></p></h2>
<h2>Http Code: <em data-bind='text:httpCode'></em></h2>
</script>

</head>
<body>

<p>Custom component</p>

<hr>
<!-- 1st Way : Consuming Component - http-error, with passing params-->
<div data-bind="component: {name: 'http-error', params: { msg: 'File not found', code: 404}}"></div>
<hr>

<!-- 2nd Way : Consuming Component - http-error , without sending params, so that default thing will display-->
<div data-bind="component: 'http-error'"></div>

<hr>
<!-- 3rd Way : Consuming Component -->
<http-error params="{msg: 'Server Error', code: 500}"></http-error>
</body>
</html>

###########################################################################

<!DOCTYPE html>
<head>
<title>KnockoutJS Templating - Named Template</title>
<script src = "https://ajax.aspnetcdn.com/ajax/knockout/knockout-3.3.0.js"
type = "text/javascript"></script>
</head>

<body>
<h2>Friends List</h2>
Here are the Friends from your contact page:
<div data-bind = "template: { name: 'friend-template', data: friend1 }"></div>
<div data-bind = "template: { name: 'friend-template', data: friend2 }"></div>

<script type = "text/html" id = "friend-template">
<h3 data-bind = "text: name"></h3>
<p>Contact Number: <span data-bind = "text: contactNumber"></span></p>
<p>Email-id: <span data-bind = "text: email"></span></p>
</script>

<script type = "text/javascript">
function MyViewModel() {
this.friend1 = {
name: 'Smith',
contactNumber: 4556750345,
email: 'smith123@gmail.com'
};
this.friend2 = {
name: 'Jack',
contactNumber: 6789358001,
email: 'jack123@yahoo.com'
};
}

var vm = new MyViewModel();
ko.applyBindings(vm);
</script>
</body>
</html>


Custom Java Logic

Custom Java Logic 1. Remove Particular Html tag from String. Requirement - Remove <font> tags, even if it has multiple then rem...