Simulate Angular Binding with Pure JavaScript

0

Is it possible to simulate Angular data binding in pure javascript?

Example:

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script><body><divng-app="">
 
<p>Input something in the input box:</p>
<p>Name : <input type="text" ng-model="name" placeholder="Enter name here"></p>
<h1>Hello {{name}}</h1>

</div>

</body>
</html>

Code removed from W3schools

    
asked by anonymous 14.10.2018 / 21:39

1 answer

1

Spreading with pure JS would be something like:

<!DOCTYPE html>
    <html>
        <body>

            <div>
                <p>Input something in the input box:</p>
                <p>Name : <input type="text" id="inputNome" placeholder="Enter name here" onChange="mudouInput()"></p>
                <h1 id="nome">Hello </h1>

            </div>

            <script type="text/javascript">
            	function mudouInput() {
            		inputValue = document.getElementById('inputNome').value;
    		        document.getElementById('nome').innerHTML = "Hello " + inputValue;
        	    }
            </script>
        </body>
    </html>
    
14.10.2018 / 22:02