本文介绍了angularjs实现的购物金额计算工具。分享给大家参考,如下:
当我们用js或jquery计算购物车的数量时,会很麻烦。今天,我们使用angularjs作为计算购物车总量的新方法。代码如下:
!doctype html html ng-app head meta charset=' utf-8 ' titlewww.jb51.net Angular Shopping Amount Calculator/title/headsdy ng-controller=' sum ' price :输入类型=' text ' ng-model=' cup . price ' br/br/quantity :输入类型=' text ' ng-model=' cup . count ' pFreight : { { cup . fee | currency : ' ' } }/p总金额为3: { { all()| p-filter currency-/body script src=' http : angular . min . js '/script script//function sum($ scope){ $ scope . cup={ ' price ' :12,' count' :1,' fee ' :20 } $ scope . all=function(){ return $ scope . cup . price * $ scope . cup . count;}//$ watch//monitor change//有三个参数//1。函数或属性//2.callback //3.true深入监视$ scope。$ watch ('all()',function (nval,oval){//console . log(nval ' : ')if(nval 100){ $ scope . cup . fee=20;} else { $ scope . cup . fee=0;} },true) $scope。$watch('cup.count ',function(nval,oval){//console . log(nval ' : ' oval);if(nval 1){ $ scope . cup . fee=0;}},true)}/script script/script/html运行效果:
PS:这里我们推荐几个在线计算工具,供大家参考:
在线投资和金融计算器:http://tools.jb51.net/jisuanqi/touzilicai_calc
在线存款计算器:http://tools.jb51.net/jisuanqi/cunkuan_calc
科学计算器在线使用_高级计算器在线计算:http://tools.jb51.net/jisuanqi/jsqkexue
在线计算器_标准计算器:http://tools.jb51.net/jisuanqi/jsq
更多对AngularJS感兴趣的读者可以查看本网站的主题:《AngularJS指令操作技巧总结》、《AngularJS入门与进阶教程》和《AngularJS MVC架构总结》
希望本文对AngularJS编程有所帮助。