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>
}
posted @ 2014-06-22 17:08  PengpengSong  阅读(181)  评论(0编辑  收藏  举报