根据Code School的视频完成简单angularjs1的实例
<!DOCTYPE html> <html ng-app="store"> <head> <meta charset="utf-8"><script src="../lib/angular.min.js"></script> <script type="text/javascript" src="../js/app1.js"></script> <link rel="stylesheet" type="text/css" href="../lib/bootstrap.min.css"> </head> <!-- StoreController起个别名store --> <body ng-controller="StoreController as store"> <div> <!-- 表达式获取值 --> <h1>{ {store.product.name}}</h1> <h2>{ {store.product.price}}</h2> <p>{ {store.product.description}}</p> <!-- ng-show判断是否显示 --> <button ng-show="store.product.canPurchase"> Add to Cart </button> </div> </body> </html> |
/*定义模块,[]是依赖的下面模块*/ var app = angular.module('store',[]); /*定义一个控制器*/ app.controller('StoreController',function(){ this.product = gem; });var gem = { name:'Dodecahedron', price:2, description:'...', /*修改canPurchase,可以决定按钮是否显示*/ canPurchase:true, }; |