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
    • 781
    Comment on it

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

    Html -

    <div ng-app="nameApp" ng-controller="TitleCtrl">
        <ul>
          <li ng-repeat="name in names">{{name}}
          <a href="" ng-click="removeName(name)">remove</a></li>
        </ul>
        <form ng-submit="addName()">
          <input type="text" ng-model="enteredName">
          <input type="submit" value="+">
        </form>
      </div>
    

    Script -

      var nameApp = angular.module('nameApp', []);
      nameApp.controller('TitleCtrl', function ($scope){
        $scope.names = ['FindNerd'];
    
        $scope.addName = function() {
          $scope.names.push($scope.enteredName);
          $scope.enteredName = '';
        };
    
        $scope.removeName = function(name) {
          var i = $scope.names.indexOf(name);
          $scope.names.splice(i, 1);
        };
      });
    

    Output -

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: