구매 금액 실례 조작

2830 단어
필터 일반 연산 작업
currency: 화폐 방법

비용: {{iphone.money* iphone.num | currency:'€'}


$watch 감청: $scope 위에 마운트된
세 번째 매개 변수, 집합에 대한 모든 변환 감청
$scope.$watch('iphone.money',function(){
})
$scope.$watch('iphone.num',function(){
})
$scope.$watch('iphone',function(){
},true)
$scope.$watch('아이폰','function(신규값신참, 구값신참){
},true)
감청 함수:
<html ng-app>
<head>
<title>Demo1</title>
<meta charset="UTF-8"/>
<script type="text/javascript" src="jquery-1.11.1.js"></script>
<script type="text/javascript" src="angular.min.js"></script>
<script>
function Aaa($scope,$timeout){
$scope.iphone = {
'money' : 5,
'num' : 1,
'fre' : 10
};
$scope.sum = function(){
return $scope.iphone.money * $scope.iphone.num 
}
$scope.$watch('iphone',function(){
},true)
$scope.$watch($scope.sum,function(newValue,oldValue){
alert(newValue);
})
}
</script>
</head>
<body>
<div ng-controller="Aaa">
<p> :<input type="text" ng-model='iphone.money'></p>
<p> :<input type="text" ng-model='iphone.num'></p>
<p> :<span>{{ sum() | currency:'¥'}}</span></p>
<p> :<span>{{ iphone.fre | currency:'¥'}}</span></p>
<p> :<span>{{ sum() + iphone.fre}}</span></p>
</div>
</body>
</html>
<html ng-app>
<head>
<title>Demo1</title>
<meta charset="UTF-8"/>
<script type="text/javascript" src="jquery-1.11.1.js"></script>
<script type="text/javascript" src="angular.min.js"></script>
<script>
function Aaa($scope,$timeout){
$scope.iphone = {
'money' : 5,
'num' : 1,
'fre' : 10
};
$scope.sum = function(){
return $scope.iphone.money * $scope.iphone.num 
}
$scope.$watch('iphone',function(){
},true)
$scope.$watch($scope.sum,function(newValue,oldValue){
$scope.iphone.fre = newValue >= 100 ? 0 : 10;
console.log(newValue);
})
}
</script>
</head>
<body>
<div ng-controller="Aaa">
<p> :<input type="text" ng-model='iphone.money'></p>
<p> :<input type="text" ng-model='iphone.num'></p>
<p> :<span>{{ sum() | currency:'¥'}}</span></p>
<p> :<span>{{ iphone.fre | currency:'¥'}}</span></p>
<p> :<span>{{ sum() + iphone.fre}}</span></p>
</div>
</body>
</html>

좋은 웹페이지 즐겨찾기