ng-summit and $watch() funciton

<div ng-app>

    <form ng-submit="requestFunding()" ng-controller="StartUpController">

        Starting: <input ng-model="startingEstimate">

        Recommendation: {{needed}}

        <button type="submit" class="btn">Fund my startup!</button>

        <button type="reset" class="btn" ng-click="reset()">Reset</button>

    </form>

</div>

@section scripts{

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

    <script>

        function StartUpController($scope) {

            $scope.startingEstimate = 0;



            computeNeeded = function () {

                $scope.needed = $scope.startingEstimate * 10;

            };



            $scope.requestFunding = function () {

                window.alert("Sorry, please get more customers first.");

            };



            $scope.reset = function () {

                $scope.startingEstimate = 0;

            };



            // observe the model 'startingEstimate', if value changed, call computeNeeded function

            $scope.$watch('startingEstimate', computeNeeded);

        }

    </script>

}

你可能感兴趣的:(SUM)