Click here to Skip to main content
15,895,516 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello
I am creating numeric inputs dynamically and I want to bind each numeric input value to it's related "p" element. I have written the code in jsfiddle. each "p" element supposes to show the related selected number in the numeric input, but it doesn't. For example if I change the firs numeric input value, it's "p" element should be changed and show the current value, but "p" element is not being displayed.
could you please where in my code is wrong?
Best regards

What I have tried:

I have written my code in jsfiddle.
Posted
Updated 7-Jul-17 23:04pm
v2

1 solution

try

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
     <script>
         var app = angular.module('myModule', []);
         app.controller('myController', function ($scope, $compile) {
             $scope.myfunction = function () {
                 var dyn = angular.element(document.getElementById("test"));
                 $compile(dyn)($scope);
             }
         });
         $(document).ready(function () {
             for (i = 0; i <= 4; i++) {
                 var _input = document.createElement("input");
                 _input.setAttribute("type", "number");
                 _input.setAttribute("ng-model", "quantity" + i);
                 var _result = document.createElement("p");
                 _result.setAttribute("ng-bind", "quantity" + i);
                 document.getElementById("test").appendChild(_input);
                 document.getElementById("test").appendChild(_result);
             }

             angular.element(document.getElementById('test')).scope().myfunction()
         }); 

     </script>
</head>
<body >
    <div id="test" ng-app="myModule" ng-controller="myController">

    </div>
</body>
</html>
 
Share this answer
 
Comments
Karthik_Mahalingam 8-Jul-17 5:07am    
Ali Majed HA 8-Jul-17 5:33am    
Thanks a lot. That was great. Would you please tell me what was my main mistake?
Karthik_Mahalingam 8-Jul-17 22:58pm    
dynamic elements should be compiled by angular
Ali Majed HA 8-Jul-17 23:31pm    
Thanks again.
Karthik_Mahalingam 9-Jul-17 2:13am    
welcome

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