Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I created a HTML5 canvas code to generate rectangular blocks and used JavaScript to create a new block every time a button is clicked. And, every time the block is clicked, some data is displayed. This data is stored in the local web storage (SQLite). Now, I've done all this using HTMLL5 canvas, JavaScript, JQuery, SQLite. I'm now tasked with converting the whole thing into Angular, but I'm unfamiliar with it. Can someone please help me out.

What I have tried:

HTML

<!DOCTYPE html>
<html>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="cordova-1.7.0.js"></script>

<br><br>
<script src="myjs.js"></script>
         

<button type="button" id="button">
Create
</button>
<p id="demo"></p>
<canvas id="test" class="test"></canvas>
      <div id = "status" name = "status"></div> 

</body>
</html>


Javascript

$(document).ready(function(){

var c = document.getElementById("test");
var ctx=c.getContext("2d");
var h=ctx.fillStyle = 'hsl(' + 360 * Math.random() + ', 50%, 50%)';    
ctx.fillRect(20, 20, 150, 100);
	ctx.font="30px Arial";

	ctx.fillText(0,250,75);
			ctx.stroke();
				var db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024); 
         var msg; 
    var j=Math.random()*4;
	var k=Math.random()*4;

         db.transaction(function (tx) { 
            tx.executeSql('CREATE TABLE IF NOT EXISTS LOG11 (id,id1)'); 
            tx.executeSql('INSERT INTO LOG11 (id,id1) VALUES (?,?)',[j,k]); 
              });
		 

	c.addEventListener('click', function(event) {
            document.getElementById("demo").innerHTML="Transaction id is "+j+"<br />"+"Transaction id is "+k;
        


});
   
  

$('#button').click(function() {
     var el = $("#test"),  
     newone = el.clone(true);
     el.before(newone);//This line is added just for styling
	 

});

var i=0;

$('#button').click(function() {
	i++;
	var j=Math.random()*4;
	var k=Math.random()*4;
      
var e = document.getElementById("test");
var ctx2 = e.getContext("2d");
ctx2.fillStyle = 'hsl(' + 360 * Math.random() + ', 50%, 50%)';    
ctx2.fillRect(20, 20, 150, 100);
	
		ctx2.font="30px Arial";
	ctx2.fillText(i,250,75 );
	ctx2.stroke();

var db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024); 
var msg;
	db.transaction(function (tx) { 
            tx.executeSql('INSERT INTO LOG11 (id,id1) VALUES (?,?)',[j,k]); 
         });
		 
	
	e.addEventListener('click', function(event) {
            document.getElementById("demo").innerHTML="Transaction id is "+j+"<br />"+"Transaction id is "+k;

    
});

});
});
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900