单击按钮如何更新对象的值

时间:2019-12-19 21:32:14

标签: angularjs

我需要在单击按钮时更新对象employee.points的值。但是我的代码中有一些问题。我该怎么解决?

<!DOCTYPE html>
<html lang=en-US>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular-route.js"></script>

</head>
<body>

    <h1> Employe page</h1>
    <div ng-app="myapps" ng-controler="power" ng-init="employe={name:'arjun',attendence:1,points:1}">
    <h4> Name: <span ng-bind="employe.name"></span></h4>
    <ol>
        <li><p>
            Attendence: <span ng-bind="employe.attendence"></span></p>
        </li>
        <li> <input type="text " ng-model="candidate_name" value="Candidate name">
            <input type="number " ng-model="candidate_phone" value="944-"><br>
            <button ng-click="increase()">Enter</button>
    </ol>
    <p> Points: <span ng-bind="employe.points"></span> </p>
</div>
</body>
<script>
        var app=angular.module('myapps',[]);
        app.controller('power',function($scope)
        {
            $scope.employe.name="kalyan";
            $scope.increase=function()
            {
                $scope.employe.points++;
            }
            console.log($scope.employe.points);

        })
    </script>
</html>

0 个答案:

没有答案