नॉकआउट के साथ, मैं कह सकता हूँमैं AngularJS को प्रत्येक बार परिवर्तन का उपयोग करने वाले डेटा को फिर से कैसे कार्यान्वित कर सकता हूं?
<html>
<head>
<script type="text/javascript" src="knockout-2.1.0.js"></script>
</head>
<body>
<input type="text" data-bind="value: a"></input> +
<input type="text" data-bind="value: b"></input> =
<span data-bind="text: result"></span>
<script type="text/javascript">
function ExampleViewModel() {
this.a = ko.observable(5);
this.b = ko.observable(6);
this.result = ko.computed(function() {
return parseInt(this.a()) + parseInt(this.b());
}, this);
}
ko.applyBindings(new ExampleViewModel());
</script>
</body>
</html>
और result
हर बार ए और बी परिवर्तन पुनर्गणना कर दिया जाएगा। मैं AngularJS को मेरे लिए ऐसा करने के लिए कैसे प्राप्त कर सकता हूं? मैं
<html ng-app>
<head>
<script type="text/javascript" src="angular-1.0.1.min.js"></script>
<script type="text/javascript">
function ExampleCtrl($scope) {
$scope.a = 5;
$scope.b = 6;
$scope.result = function() {
return this.a + this.b
};
}
</script>
</head>
<body ng-controller="ExampleCtrl">
<input type="text" value="{{ a }}"></input> +
<input type="text" value="{{ b }}"></input> =
{{ result() }}
</body>
</html>
की कोशिश की है एक छोटे से अधिक पढ़ने के बाद, मैं ng-change
पाया:
<html ng-app>
<head>
<script type="text/javascript" src="angular-1.0.1.min.js"></script>
<script type="text/javascript">
function ExampleCtrl($scope) {
$scope.a = 5;
$scope.b = 6;
$scope.result = function() {
return parseInt($scope.a) + parseInt($scope.b)
};
}
</script>
</head>
<body ng-controller="ExampleCtrl">
<input type="text" ng-model="a" ng-change="result()"></input> +
<input type="text" ng-model="b" ng-change="result()"></input> =
{{ result() }}
</body>
</html>
लेकिन है कि मुझे इस तथ्य का ट्रैक रखने के बदलते a
या b
बदलता है result()
कि करने के लिए की आवश्यकता है, वहाँ किसी भी स्वचालित मार्ग नहीं है इसका पता लगाने का?
आप $ की कोशिश की है देखते हैं? http://docs.angularjs.org/api/ng.$rootScope.Scope – Eduardo