#ng-value可以填写表达式 <!DOCTYPEhtml> <html> <head> <Metacharset="UTF-8"> <title></title> <scripttype="text/javascript"src='js/angular.min.js'></script> <styletype="text/css"> .ng-cloak{display:none;} </style> </head> <bodyng-app="hd"ng-cloakclass="ng-cloak"> <divng-controller="ctrl"> 商品名称:<inputtype="text"ng-model="goods.name"/><br/> 商品价格:<inputtype="text"ng-model="goods.price"/><br/> 商品数量:<inputtype="text"ng-model="goods.num"/><br/> 商品总价:<inputtype='text'ng-value="goods.price*goods.num"readonly="readonly"/><br/> </div> <scripttype="text/javascript"> varm=angular.module('hd',[]) m.controller('ctrl',['$scope',function($scope){ $scope.goods={'name':'iphone','price':3000,'num':0} }]) </script> </body> </html>
#ng-show关联单选框 <!DOCTYPEhtml> <html> <head> <Metacharset="UTF-8"> <title></title> <scripttype="text/javascript"src='js/angular.min.js'></script> <styletype="text/css"> .ng-cloak{display:none;} </style> </head> <bodyng-app="hd"ng-cloakclass="ng-cloak"> <divng-controller="ctrl"> 显示<inputtype="radio"ng-model="status"ng-value="1"/><br/> 关闭<inputtype="radio"ng-model="status"ng-value=""/><br/> {{status}} <textng-show="status==1">正在维护中...</text> </div> <scripttype="text/javascript"> varm=angular.module('hd',function($scope){ $scope.status=1 }]) </script> </body> </html>
#复选框checkBox,控制选中的值:ng-true-value="1"ng-false-value="0" <!DOCTYPEhtml> <html> <head> <Metacharset="UTF-8"> <title></title> <scripttype="text/javascript"src='js/angular.min.js'></script> <styletype="text/css"> .ng-cloak{display:none;} </style> </head> <bodyng-app="hd"ng-cloakclass="ng-cloak"> <divng-controller="ctrl"> 游戏<inputtype="checkBox"ng-model="data.game"ng-true-value="1"ng-false-value="0"/><br/> 电影<inputtype="checkBox"ng-model="data.movie"ng-true-value="1"ng-false-value="0"/><br/> {{data.game}} <textareang-show="data.game==1">dota2</textarea> <textareang-show="data.movie">战狼2</textarea> </div> <scripttype="text/javascript"> varm=angular.module('hd',function($scope){ $scope.data={'game':0,'movie':0} }]) </script> </body> </html>
#下拉列表select,ng-options <!DOCTYPEhtml> <html> <head> <Metacharset="utf-8"/> <title></title> <scriptsrc="js/angular.min.js"></script> </head> <body> <divng-app="app"ng-controller="ctrl"> <selectng-options="v.valueasv.nameforvindata"ng-model="hobby"> <optionvalue="">请选择hobby</option> </select> {{hobby}} </div> <scripttype="text/javascript"> varm=angular.module('app',[]); m.controller('ctrl',function($scope){ $scope.hobby='iphone' $scope.data=[ {name:'game',value:'dota2'},{name:'movie',value:'战狼2'},{name:'phone',value:'iphone'} ] }]); </script> </body> </html>