感谢您的支持,我会继续努力的!
打开微信扫一扫,即可进行扫码打赏哦
点我查看本站打赏源码!
Powered by RUNCODEX.COM,学的不仅是技术,更是梦想!!!
<script src="https://cdn.staticfile.org/angular.js/1.6.6/angular.min.js"></script>
<p>
乘法运算:
</p>
<div ng-app='myApp' ng-controller='MathCtrl'>
<input type="text" ng-model='leftNum'> x
<input type="text" ng-model='rightNum'>
=<span >{{multRes}}</span>
</div>
xxxxxxxxxx
var app = angular.module('myApp',[]);
// 乘法
app.factory('MathFac', [function () {
var factory = {};
factory.mult = function(){
var res = 1;
for(var i = 0 ; i < arguments.length ; i++){
res *= arguments[i];
}
return res;
return factory;
}]);
app.service('CalcService', function (MathFac) {
this.square = function(){
return MathFac.mult.apply(null,arguments);
});
app.controller('MathCtrl', function ($scope,CalcService) {
$scope.leftNum = 3;
$scope.rightNum = 5;
$scope.multRes = 15;
$scope.$watch('leftNum',function(){
$scope.getMultRes($scope.leftNum,$scope.rightNum)
$scope.$watch('rightNum',function(){
$scope.getMultRes = function(){
$scope.multRes = CalcService.square.apply(null,arguments);
输入 CSS 代码……