【AngularJs-模块篇-Form篇】

本文介绍了AngularJS的基础用法,包括如何使用模块初始化应用,通过控制器绑定数据到视图,并利用表单控件实现数据交互。文章还展示了如何通过ng-model进行双向数据绑定,以及如何使用自定义函数响应用户操作。

1、模块

<!doctype html>
<html lang="en-US" ng-app="myApp">
<head>
    <meta charset="UTF-8">
    <title></title>
    <!-- <script src="http://code.angularjs.org/angular-1.0.1.min.js"></script> -->
    <script src="../angular.min.js"></script>
    <script type="text/javascript">
       var myAppModule=angular.module('myApp',[])  ;
        myAppModule.controller('TextController',function($scope){
            var someText={};
            someText.message="you have started";
            $scope.someText=someText;

        }) ;
        //ng-bind和{{someText}}具有相同功能
    </script>
</head>
<body ng-controller="TextController">
                                  <p ng-bind="someText"></p>
          <input type="text" value="{{someText.message}}">
</body>
</html>
View Code

2、Form控件绑定(未完成)

<!doctype html>
<html lang="en-US" ng-app="myApp">
<head>
    <meta charset="UTF-8">
    <title></title>
    <!-- <script src="http://code.angularjs.org/angular-1.0.1.min.js"></script> -->
    <script src="../angular.min.js"></script>
    <script type="text/javascript">

        var myAppModule=angular.module('myApp',[])  ;
        myAppModule.controller('StartUpController',function($scope){
            $scope.computeNeeded=function(){
                $scope.needed=$scope.startingEstimate*10;
            };
            $scope.requestFunding=function(){
                window.alert("sorry,please get moure cutomers first");
            };
            $scope.reset=function(){
                $scope.startingEstimate=0;
            } ;

        }) ;


    </script>
</head>
<body>
<form ng-submit="requestFunding()"  ng-controller="StartUpController">
      Starting:<input ng-change="computeNeeded()" ng-model="startingEstimate">
    Recommendation:{{needed}}
    <button>Fund my startup!</button>
    <button ng-click="reset()" value="reset">reset</button>
   

</form>

</body>
</html>
View Code

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值