We are providing online training of realtime Live project on Asp.Net MVC with Angular and Web API. For more information click here. If you have any query then drop the messase in CONTACT FORM

Friday, April 27, 2018

How to pass the data from controller to view without using $scope in AngularJs

<link href="~/Content/bootstrap.css" rel="stylesheet" />
<script src="~/Scripts/angular.js"></script>
<h2>Employee Details</h2>
<br />
<script type="text/javascript">
    angular.module('myApp', [])
    .controller('MyController', [function () {
        var emp = this;
        emp.employees = [
        { id: 1, empName: 'Mithilesh', address: 'Hyderabad',phoneNo:'1232345476' },
        { id: 2, empName: 'Sanjeev', address: 'Delhi', phoneNo: '1229645476' },
        { id: 3, empName: 'Sonu ', address: 'Mumbai', phoneNo: '1232389276' },
        { id: 4, empName: 'Firoz', address: 'Banglore', phoneNo: '1232345476' }
        ];
    }]);
</script>


<body class="row" ng-app="myApp" ng-controller="MyController as ctrl">
    <div class="col-md-7">
        <table class="table">
            <tr class="btn-primary">
                <th>Employee Id</th>
                <th>Employee Name</th>
                <th>Address</th>
                <th>Phone Number</th>
            </tr>
            <tr class="btn-info" ng-repeat="details in ctrl.employees">
                <td>{{details.id}}</td>
                <td>{{details.empName}}</td>
                <td>{{details.address}}</td>
                <td>{{details.phoneNo}}</td>
            </tr>
        </table>
    </div>

</body>

Output:

No comments: