Javascript 角JS将字符串数组传递到指令

Javascript 角JS将字符串数组传递到指令,javascript,arrays,angularjs,angularjs-directive,angular-ngmodel,Javascript,Arrays,Angularjs,Angularjs Directive,Angular Ngmodel,我有下面的指令,它从数组数据输出数字和相应的字符串值 var-app=angular.module(“测试”,[]); 应用控制器(“Ctrl1”,功能($scope){ $scope.range=5; $scope.data=['a','b','c','d','e',]; }); app.directive(“myDirective”,function()){ 返回{ 限制:“EA”, 范围:正确, 模板:“{n+1}}-{data[n]}” }; }) .filter('范围',函数())

我有下面的指令,它从数组数据输出数字和相应的字符串值

var-app=angular.module(“测试”,[]);
应用控制器(“Ctrl1”,功能($scope){
$scope.range=5;
$scope.data=['a','b','c','d','e',];
});
app.directive(“myDirective”,function()){
返回{
限制:“EA”,
范围:正确,
模板:“{n+1}}-{data[n]}”
};
})
.filter('范围',函数()){
返回函数(输入,总计){
总计=parseInt(总计);

for(var i=0;i
将把新值写入字符串而不是数组。您需要将字符串拆分为数组。请参见更好的方法是使用一个函数来推送和弹出数组中的输入数据。如下所示:

HTML:

<input type="text" ng-model="inputdata" ng-click="pushDataInArray(inputdata);"></input>
//And similarly have a function to pop the data from whichever index from the array.
这将是一个更好的方法

$scope.pushDataInArray = function(inputdata){
 $scope.data.push(inputdata);
};