好的,我似乎无法启动$ scope.watch。
$scope.amountselected = 5;
$scope.qtyselected = 1;
$scope.$watch(['qtyselected'], function () {
console.log($scope.availbleprecheckout);
});
jQuery(document).ready(function($) {
jQuery('#weight').on('change', function() {
$scope.amountselected = parseInt(this.value);
$scope.$digest();
});
jQuery('.input-text.qty').bind('change', function(){
$scope.$apply(function(fn){
$scope.qtyselected ='AHHHHH';
});
});
});
$scope.$watch(['qtyselected','amountselected'], function () {
console.log('quantity:'+$scope.qtyselected);
console.log('weight:'+$scope.amountselected);
console.log('avail:'+$scope.availbleprecheckout);
});
我试过$ scope。$ apply $ scope.digest,我试过将$ scope。$ watch嵌套在.on('change'内的文档中,但似乎无济于事。为什么
如果要使用$watch
,则应将监视变量的名称作为字符串而不是字符串数组放置。
简单使用:
$scope.$watch('qtyselected', function(){
});
如果要监视多个变量,可以使用:
$scope.$watchCollection('[qtyselected,amountselected]',function(){
});
或者
$scope.$watch('qtyselected+amountselected',function(){
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句