JavaScript - Simple Binding Element Using AngularJS

In this tutorial we will create a Simple Binding Element using AngularJS. AngularJS is a JavaScript-based open-source front-end web application framework . It is a kind of template that extends HTML to a new level of coding techniques. It is mostly used by other well known site for creating a template.

Getting started:

First you have to download & install the AngularJS here's the link https://angularjs.org/. And, this is the link for the bootstrap that i used for the layout design https://getbootstrap.com/.

Creating the Main Interface

This code contains the interface of the application. This code will render application and display the form. To do that just kindly write these block of code inside the text editor and save this as index.html.
  1. <!DOCTYPE html>
  2. <html lang="en" ng-app="myModule">
  3.         <head>
  4.                 <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
  5.                 <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
  6.         </head>
  7. <body ng-controller="myController">
  8.         <nav class="navbar navbar-default">
  9.                 <div class="container-fluid">
  10.                         <a class="navbar-brand" href="https://sourcecodester.com">Sourcecodester</a>
  11.                 </div>
  12.         </nav>
  13.         <div class="col-md-3"></div>
  14.         <div class="col-md-6 well">
  15.                 <h3 class="text-primary">JavaScrip - Simple Binding Element Using AngularJS</h3>
  16.                 <hr style="border-top:1px dotted #ccc;"/>
  17.                 <div class="col-md-3"></div>
  18.                 <div class="col-md-6">
  19.                         <textarea class = "form-control" style = "resize:none; height:150px;" ng-model = "msg" placeholder="Please enter something"></textarea>
  20.                         <br />
  21.                         <div>{{msg}}</div>
  22.                 </div>
  23.         </div>
  24. <script src="js/angular.js"></script>
  25. <script src="js/script.js"></script>
  26. </body>
  27. </html>

Creating the Script

This code contains the main function of the application. This code will dynamically display the data without submitting it. To that just kindly copy and write these block of codes inside the text editor, then save it inside the js directory as script.js.
  1. var app = angular.module("myModule", []);
  2.  
  3. app.controller("myController", function($scope){
  4.         var msg = "This is a default message for the bind element";
  5.        
  6.         $scope.msg = msg;
  7. });
There you have it we successfully created a Simple Binding Element using AngularJS. I hope that this very simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!!

Add new comment