Javascript 无法从表AngularJS中识别$scope方法

Javascript 无法从表AngularJS中识别$scope方法,javascript,angularjs,angularjs-scope,html-table,Javascript,Angularjs,Angularjs Scope,Html Table,我使用ng repeat通过表单绑定数组。这是代码 HTML: <form> <table> <tr data-ng-repeat="x in names"> <td><textarea placeholder="New Name" ng-model="x.name" name="" ></textarea></td> <td><button

我使用ng repeat通过表单绑定数组。这是代码

HTML:

<form>
   <table>
      <tr data-ng-repeat="x in names">
         <td><textarea placeholder="New Name" ng-model="x.name" name="" ></textarea></td>
         <td><button style="background:#f00;" ng-click="removeChoice(x)">-</button></td>
      </tr>
   </table>
</form>
.controller('TerrItemCtrl', function($scope){
$ionicModal.fromTemplateUrl('templates/addAddress.html', {
   scope: $scope,
   animation: 'animated bounceInDown',
   hideDelay: 920
}).then(function (modal) {
   $scope.names = [{ 'id': 'name1'}];
   $scope.modal = modal;
   $scope.modal.show();
});
$scope.removeChoice = function (x) {
    for (i = 0; i < $scope.names; i++) {
        if ($scope.names[i].id === x.id) {
            $scope.names.splice(i);
            break;
        }
    }
};
});

-
Javascript:

<form>
   <table>
      <tr data-ng-repeat="x in names">
         <td><textarea placeholder="New Name" ng-model="x.name" name="" ></textarea></td>
         <td><button style="background:#f00;" ng-click="removeChoice(x)">-</button></td>
      </tr>
   </table>
</form>
.controller('TerrItemCtrl', function($scope){
$ionicModal.fromTemplateUrl('templates/addAddress.html', {
   scope: $scope,
   animation: 'animated bounceInDown',
   hideDelay: 920
}).then(function (modal) {
   $scope.names = [{ 'id': 'name1'}];
   $scope.modal = modal;
   $scope.modal.show();
});
$scope.removeChoice = function (x) {
    for (i = 0; i < $scope.names; i++) {
        if ($scope.names[i].id === x.id) {
            $scope.names.splice(i);
            break;
        }
    }
};
});
.controller('TerrItemCtrl',函数($scope){
$ionicModal.fromTemplateUrl('templates/addAddress.html'{
范围:$scope,
动画:“动画反弹区”,
希德雷:920
}).then(功能(模态){
$scope.names=[{'id':'name1}];
$scope.modal=modal;
$scope.modal.show();
});
$scope.removeChoice=函数(x){
对于(i=0;i<$scope.names;i++){
if($scope.names[i].id==x.id){
$scope.names.splice(i);
打破
}
}
};
});
我在这个表单的控制器中有一个$scope.removeChoice函数,html找不到它。我相信这是因为我使用的数组,但这是我将(-)按钮放在输入标记右侧的唯一方法。有没有办法绕过这个

试试这个

var-app=angular.module(“myApp”,[]);
app.controller(“myCtrl”,函数($scope){
$scope.names=[“a”、“b”、“c”];
$scope.removeChoice=函数(x){
$scope.names.splice(x,1);
}
})

-
试试这个

var-app=angular.module(“myApp”,[]);
app.controller(“myCtrl”,函数($scope){
$scope.names=[“a”、“b”、“c”];
$scope.removeChoice=函数(x){
$scope.names.splice(x,1);
}
})

-

ng repeat
引入一个新范围。因此,要访问父级,必须使用
$parent.someMethodInParentScope()

var-app=angular.module(“myApp”,[]);
app.controller(“myCtrl”,函数($scope){
$scope.names=[“a”、“b”、“c”];
$scope.removeChoice=函数(x){
$scope.names.splice(x,1);
}
})

-

ng repeat
引入一个新范围。因此,要访问父级,必须使用
$parent.someMethodInParentScope()

var-app=angular.module(“myApp”,[]);
app.controller(“myCtrl”,函数($scope){
$scope.names=[“a”、“b”、“c”];
$scope.removeChoice=函数(x){
$scope.names.splice(x,1);
}
})

-
尝试使用以下方法:

.controller('TerrItemCtrl',['$scope', function($scope){
$ionicModal.fromTemplateUrl('templates/addAddress.html', {
   scope: $scope,
   animation: 'animated bounceInDown',
   hideDelay: 920
}).then(function (modal) {
   $scope.names = [{ 'id': 'name1'}];
   $scope.modal = modal;
   $scope.modal.show();
});
$scope.removeChoice = function (x) {
    for (i = 0; i < $scope.names; i++) {
        if ($scope.names[i].id === x.id) {
            $scope.names.splice(i);
            break;
        }
    }
};
}]);
.controller('TerrItemCtrl',['$scope',函数($scope){
$ionicModal.fromTemplateUrl('templates/addAddress.html'{
范围:$scope,
动画:“动画反弹区”,
希德雷:920
}).then(功能(模态){
$scope.names=[{'id':'name1}];
$scope.modal=modal;
$scope.modal.show();
});
$scope.removeChoice=函数(x){
对于(i=0;i<$scope.names;i++){
if($scope.names[i].id==x.id){
$scope.names.splice(i);
打破
}
}
};
}]);
尝试使用以下方法:

.controller('TerrItemCtrl',['$scope', function($scope){
$ionicModal.fromTemplateUrl('templates/addAddress.html', {
   scope: $scope,
   animation: 'animated bounceInDown',
   hideDelay: 920
}).then(function (modal) {
   $scope.names = [{ 'id': 'name1'}];
   $scope.modal = modal;
   $scope.modal.show();
});
$scope.removeChoice = function (x) {
    for (i = 0; i < $scope.names; i++) {
        if ($scope.names[i].id === x.id) {
            $scope.names.splice(i);
            break;
        }
    }
};
}]);
.controller('TerrItemCtrl',['$scope',函数($scope){
$ionicModal.fromTemplateUrl('templates/addAddress.html'{
范围:$scope,
动画:“动画反弹区”,
希德雷:920
}).then(功能(模态){
$scope.names=[{'id':'name1}];
$scope.modal=modal;
$scope.modal.show();
});
$scope.removeChoice=函数(x){
对于(i=0;i<$scope.names;i++){
if($scope.names[i].id==x.id){
$scope.names.splice(i);
打破
}
}
};
}]);
var-app=angular.module('myApp',[]);
app.controller('TerrItemCtrl',函数($scope){
$scope.names=[“a”、“b”、“c”];
$scope.removeChoice=函数(索引){
$scope.names.splice(索引,1);
};
});

-
var-app=angular.module('myApp',[]);
app.controller('TerrItemCtrl',函数($scope){
$scope.names=[“a”、“b”、“c”];
$scope.removeChoice=函数(索引){
$scope.names.splice(索引,1);
};
});

-
应该尝试使用此语法将作用域作为数组和函数传递。问题可能是当函数执行时,它没有在可执行上下文中传递scope变量


应该尝试使用此语法将作用域作为数组和函数传递。问题可能是当函数正在执行时,它没有在可执行上下文中传递范围变量。

请添加控制器代码。不是答案,但您的
数据ng repeat
是否应该不在
元素上?上述操作将导致多个
,您需要使用
$index
,然后使用
Collection.splice(index,1)
首先从table标记中删除ng repeat,并将其添加到tr标记中,就像在HTML中制作multple表一样。@Rayon,代码非常好,
removeChoice()
应使用
x
值作为参数调用。控制器中一定有问题…请添加控制器代码。不是答案,但您的
数据ng repeat
是否应该不在
元素上?上述操作将导致多个
,您需要使用
$index
,然后使用
Collection.splice(index,1)
首先从table标记中删除ng repeat,并将其添加到tr标记中,就像在HTML中制作multple表一样。@Rayon,代码非常好,
removeChoice()
应使用
x
值作为参数调用。控制器中一定发生了什么事…@KrupeshKotecha您正在
表中使用
ng repeat
tag@KrupeshKotecha您使用的是
ng-re