0

這裏是指令角指令模板陣列中的控制器功能

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

固定它!!而不是指令是一個完全不同的模塊,我將指令更改爲控制器模塊的指令,我嘗試訪問該值。

相關問題