这是指令
directives.directive("unitDirective", function(){
return {
templateUrl: "../html/directives/unitDir.html"
}
});
这是模板
<div ng-repeat="unit in addUnit()">
<label class="item item-input">
<span class="input-label">Unit {{unit+1}}</span>
<input type="number" placeholder="enter estimated monthly rent" ng-model="units.price[$index]">
</label>
</div>
这是我希望按钮
的地方<ion-view>
<ion-content>
<unit-directive></unit-directive>
<button class="button buttomn-assertive">Confirm</button>
</ion-content>
</ion-view>
这是我的控制器:
controllers.controller("unitsCtrl", function($scope, $stateParams){
$scope.units = {
price: [1,2]
}
$scope.addUnit = function(){
var dummyArray = [];
for(var i =0; i < $stateParams.units; i++){
dummyArray[i] = i;
}
return dummyArray;
};
$scope.calculate= function(){
//how do I access the array of units prices here?
}
});
基本上,我使用cordovadialog插件询问他们想要创建多少个单元然后我用提供的数字制作一个虚拟阵列并将其用于ng-repeat。现在,我必须接收所有输入并将它们存储在一个数组中,我被卡住了。 任何其他可能的重复问题,解决方案或文档/教程的任何一般方向将受到高度赞赏。
答案 0 :(得分:0)
修好了!!而不是指令是一个完全不同的模块,我将指令更改为控制器模块的指令,我试图访问该值。