前端之家收集整理的这篇文章主要介绍了
angular之$scope,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
$scope服务是方法与属性的集合
$scope用于试图进行交互,使用ng-bind或者ng-model等指
数据绑定使用:{{expr}}
<!DOCTYPE html> <html> <head> <Meta charset="UTF-8"> <title></title> <script src="http://code.angularjs.org/angular-1.0.1.min.js"></script> </head> <body ng-app="hd"> <div ng-controller="ctrl"> 商品名称:{{goods.data.title}} <br /> 价格:{{goods.data.price}} <br /> 数量:{{goods.data.num}} <br /> 总计:{{goods.data.price*goods.data.num}} <br /> <button ng-click="goods.add()">增加+</button> <button ng-click="goods.reduce()">减少-</button> </div> <script type="text/javascript"> var s=angular.module("hd",[]); s.controller("ctrl",['$scope',function($scope){ $scope.goods={ data:{"title":"apple","price":300,"num":0},add:function(){ $scope.goods.data.num=Math.min(++$scope.goods.data.num,6); },reduce:function(){ $scope.goods.data.num=Math.max(--$scope.goods.data.num,0); } }; }]); </script> </body> </html>
原文链接:https://www.f2er.com/angularjs/148418.html