Tuesday 2 May 2017

anguler js sample



    <script>


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

        (function (app) {
            "use strict";
            app.controller("productController", function ($scope, $http) {
               
                $scope.SendData = function (Data) {
                    alert('ff');
                    var GetAll = new Object();
                    GetAll.FirstName = Data.firstName;
                    GetAll.SecondName = Data.lastName;
                    GetAll.SecondGet = new Object();
                    GetAll.SecondGet.Mobile = Data.mobile;
                    GetAll.SecondGet.EmailId = Data.email;
                    $http({
                        url: "NewRoute/firstCall",
                        dataType: 'json',
                        method: 'POST',
                        data: GetAll,
                        headers: {
                            "Content-Type": "application/json"
                        }
                    }).success(function (response) {
                        $scope.value = response;
                    })
                       .error(function (error) {
                           alert(error);
                       });
                }

            });
        })(myApp);



   
    </script>

<body ng-app="myApp" ng-controller="productController">
    <hr />
    <h3>
        Send Objects of Objects Using AngularJS
    </h3>
    <hr />
    <div>
        <hr />
        <div>
            First Name:
            <input type="text" placeholder="Enter your name" ng-model="details.firstName">
            Last Name:
            <input type="text" placeholder="Enter your last name" ng-model="details.lastName">
        </div>
        <hr />
        <div>
            Mobile Number:
            <input type="text" placeholder="Enter your mobile number" ng-model="details.mobile">
            EmailId:
            <input type="text" placeholder="Enter your email id" ng-model="details.email">
        </div>
        <input type="button" ng-click="SendData(details)" value="Submit" />
        <hr />
        <h4 style="color:blueviolet">{{value}}</h4>
    </div>
    <hr />
</body>
</html>

refer: http://www.c-sharpcorner.com/article/modules-and-controller-in-angularjs/