码迷,mamicode.com
首页 > Web开发 > 详细

angularJS(2)

时间:2017-01-01 15:31:29      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:技术分享   alt   text   html5   use   init   car   pyc   type   

今天先讲一个angularJs的表单绑定实例:

技术分享
<div ng-app="myApp" ng-controller="formCtrl">
  <form novalidate>
    姓:<input type="text" ng-model="user.xing"><br>
    名:<input type="text" ng-model="user.ming"><br>
    <button ng-click="reset()">RESET</button>
  </form>
  <h2 style="color:#F00">新值 = {{user }}</h2>
  <h2>原值 = {{master}}</h2>
</div>
<script>
var app = angular.module(‘myApp‘, []);
app.controller(‘formCtrl‘, function($scope) {
    $scope.master = {xing:"张", ming:"三"};
    $scope.reset = function() {
        $scope.user = angular.copy($scope.master);
    };
    $scope.reset();
});
</script>
技术分享

注:novalidate 属性是在 HTML5 中新增的。禁用了使用浏览器的默认验证。

接下来写两个angularJs循环列举数组

<div ng-app=“” ng-init=“car=[‘宝马’,‘奥迪’,‘奔驰‘,’保时捷’,’法拉利’]">  <p>使用 ng-repeat 来循环数组</p>  <ul>    <li ng-repeat="x in car"> {{ x }}  </li>  </ul></div> 
<div ng-app=“” ng-init=“names=[{name:‘王小波’,class:‘傻子班’},{name:‘王如花’,class:‘大班’},{name:‘武则天’,class:‘预科班‘}]">
          <ul>
   <li ng-repeat="x in names">  {{ x.name + ‘, ‘ + x.class }} </li>
            </ul>
</div>

angularJS(2)

标签:技术分享   alt   text   html5   use   init   car   pyc   type   

原文地址:http://www.cnblogs.com/alinaxia/p/6241022.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!