angularjs - 在 ng-repeat AngularJS 中使用 ng-model

标签 angularjs

我在 Angular 方面遇到了一些问题。现在我有以下代码:

<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>

我想知道为什么我不能在 Controller 中console.log abc 值?我的英语不好,请帮助我。提前致谢

最佳答案

尝试改变

$scope.test = function() {
     console.log($scope.abc);
 }

$scope.test = function() {
     console.log(this.abc);
 }

“this”将解析为当前作用域对象,并且您应该能够在不断更改文本时打印该值。

关于angularjs - 在 ng-repeat AngularJS 中使用 ng-model,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22549456/

相关文章:

javascript - 数组推送,重复元素

javascript - 异步 XMLHttpRequest 响应后,ng-grid 未与最新数据绑定(bind)

javascript - 从父级 Angular 数据创建可编辑的子级

javascript - 带有 $http 响应的 Angular 过滤器

javascript - Angular promise 不会停止

javascript - 根据条件输出 <div>

javascript数组整理并显示多维

javascript - 'controller' 的 AngularJS 代码无法启动

javascript - 从 AngularJS Controller 调用 Android 函数

angularjs - 将 ng-class 与属性/值对表达式一起使用