Wednesday, 5 December 2018

How to store input values in an array in Angular|| Basics of Angular JS ...





<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

    <title></title>

    <link href="Content/bootstrap.css" rel="stylesheet" />

    <link href="Content/bootstrap.min.css" rel="stylesheet" />

    <script src="Scripts/angular.js"></script>

    <script src="Scripts/angular.min.js"></script>

    <style>



        ul li{

            list-style-type:none;

        }



    </style>



</head>

<body ng-app="myapp" ng-controller="myctrl">

    <h1>To do List</h1>

    <form ng-submit="todoAdd()">



        <input type="text" class="form-control" placeholder="Enter name here...." ng-model="todoInput" />

        <input type="submit" value="Add" class="btn btn-success" />



    </form>

    <input type="button" value="Delete" class="btn btn-danger" ng-click="remove()" />



    <div class="form-control">



        <ul ng-repeat="x in todoList">

            <li>

                <input type="checkbox" ng-model="x.done" /> <span>{{x.todoText}}</span>

            </li>



        </ul>



    </div>

 







</body>

</html>

<script>

    var app = angular.module("myapp", []);



    app.controller("myctrl", function ($scope)

    {



        $scope.todoList = [{ todoText: 'salman masood', done: false }];



        $scope.todoAdd = function ()

        {

            $scope.todoList.push({ todoText: $scope.todoInput, done: false });

            $scope.todoInput = "";

        };



        $scope.remove = function ()

        {

            var oldList = $scope.todoList;

            $scope.todoList = [];

            angular.forEach(oldList, function (x)

            {

                if (!x.done) $scope.todoList.push(x);

            });

        };







    });







</script>

No comments:

Post a Comment

Pass Dynamically Added Html Table Records List To Controller In Asp.net MVC

Controller Code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using ...