Friday, December 6, 2013

Angularjs adding data to the list items through textbox submit button or display the data we enter in the textbox in the same page:

<!doctype html>
<html lang="en"> 
<head>
<link rel="stylesheet" href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css">
<script src="http://code.angularjs.org/angular-1.0.0.min.js"></script>
<script src="http://code.angularjs.org/angular-resource-1.0.0.min.js"></script>
</head>
<body>
<div ng-app="" ng-controller="ContactController">
    
    Email:<input type="text" ng-model="contact" />
    
    <button ng-click="add()">Add</button>
    
    <h2>Contacts</h2>
    <ul>
<li ng-repeat="contact in contacts"> {{ contact }} </li>
</ul>
    
</div>

<script>
function ContactController($scope) {
    $scope.contacts = ["viralpatel.net@gmail.com", "hello@email.com"];
    
    $scope.add = function() {
        $scope.contacts.push($scope.contact);
$scope.contact = "";
    }
}

</script>

</body>
</html>

No comments:

Post a Comment