Reputation: 373
I'm developing mobile applications using Visual Studio 2017 and Apache Cordova. I've always coded using JQuery and Javascript however i have never written a code using Typescript.
When searching the web almost everyone is using Typescript with Ionic. (thinking of starting to benefit and use the Ionic Framework) Is it the same if i use JQuery or Javascript instead of Typescript with Ionic?
Or its recommended that i learn Typescript and start using it with Ionic?
Thank you for the clarification.
This is how i usually write the code for Cordova using JQuery:
function shuffleArray(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
return array;
}
function beginGame() {
$('#info').hide();
var level = 0;
$('#game_title h2').html('Level 1');
$('#game_question h3').html('What is the most common language?');
$('#game_body').html('');
var gameBody = document.getElementById('game_body');
var columnAnswer, buttonAnswer;
var answers = [['Arabic', ''], ['Spanish', ''], ['English', 'right_answer'], ['Chinese', '']];
var arr = shuffleArray(answers);
console.log(arr);
for (var i = 0; i < arr.length; i++) {
columnAnswer = document.createElement('div');
columnAnswer.className = 'col-xs-12';
buttonAnswer = document.createElement('button');
buttonAnswer.id = 'answer_button_'+i;
buttonAnswer.className = 'btn btn-primary btn-sx answer_button ' + arr[i][1];
buttonAnswer.type = 'button';
buttonAnswer.innerHTML = arr[i][0];
//buttonAnswer.setAttribute('onclick', 'onQuoteClick(' + quotes[i].id + ')');
console.log(buttonAnswer);
columnAnswer.appendChild(buttonAnswer);
gameBody.appendChild(columnAnswer);
}
$('.answer_button').click(function () {
var button_id = $(this).attr('id');
if ($('#' + button_id).hasClass('right_answer')) {
//alert('Right Answer');
$('#info').show();
fillInformation();
} else {
alert('Wrong Answer');
}
});
}
function fillInformation() {
$('#game_title h2').html('English');
$('#info_image img').attr("src", './images/level_1.png');
$('#info_text h5').html('English Language');
}
Upvotes: 0
Views: 1106
Reputation: 2726
The main difference with what you are used to is not Typescript vs Javascript, it's vanilla Js vs Angular.
Angular is the framework upon which Ionic rests and which it is extending. The Angular framework is by default in Typescript.
But that shouldn't be a problem for you, since Typescript is backwards compatible with Javascript. Any vanilla Js code in a .ts file compiles and runs just fine (although you are losing on the benefits of Typescript if you are not following best practices).
You can also definitely use jquery, just like you are used to.
Upvotes: 2
Reputation: 149
You should be able to use JQuery and Javascript with Ionic, however, you may lose the Angular capabilities Ionic offers. You could write ES6 javascript in the ts files as well. Otherwise, I'd recommend using Typescript which isn't too difficult to learn imo. Hope this helps.
Upvotes: 1