Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Remove/add list using ng-click

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 817
    Comment on it

    Here is an simple example to add and delete list using angular ng-click

    Html -

    1. <div ng-app="nameApp" ng-controller="TitleCtrl">
    2. <ul>
    3. <li ng-repeat="name in names">{{name}}
    4. <a href="" ng-click="removeName(name)">remove</a></li>
    5. </ul>
    6. <form ng-submit="addName()">
    7. <input type="text" ng-model="enteredName">
    8. <input type="submit" value="+">
    9. </form>
    10. </div>

    Script -

    1. var nameApp = angular.module('nameApp', []);
    2. nameApp.controller('TitleCtrl', function ($scope){
    3. $scope.names = ['FindNerd'];
    4.  
    5. $scope.addName = function() {
    6. $scope.names.push($scope.enteredName);
    7. $scope.enteredName = '';
    8. };
    9.  
    10. $scope.removeName = function(name) {
    11. var i = $scope.names.indexOf(name);
    12. $scope.names.splice(i, 1);
    13. };
    14. });

    Output -

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: