我在角度方面遇到了一些问题。现在我有以下代码:
<div ng-repeat='item in items'>
<span>{{item.title}}</span>
<input ng-change="test()" ng-model='abc'> {{abc}}
<span>{{item.price| currency}}</span>
<span>{{item.price * item.quantity| currency}}</span>
<button ng-click="remove($index)">Remove</button>
</div>
<script type="text/javascript" src="libs/angular.min.js"></script>
<script>
function CartController($scope) {
$scope.items = [
{title: 'Paint pots', quantity: 8, price: 3.95},
{title: 'Polka dots', quantity: 17, price: 12.95},
{title: 'Pebbles', quantity: 5, price: 6.95}
];
$scope.test = function() {
console.log($scope.abc);
}
$scope.remove = function(index) {
$scope.items.splice(index, 1);
}
}
</script>
我想知道为什么我不能在控制器中使用console.log abc值吗?我的英语不好,请帮我。提前致谢
尝试改变
$scope.test = function() {
console.log($scope.abc);
}
至
$scope.test = function() {
console.log(this.abc);
}
“ this”将解析为当前作用域对象,并且您可以在不断更改文本的同时打印该值。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句