2016-04-29 36 views
0


我在一個應用程序上工作,我想推入一個數組中的數據,但它不工作。 也許你可以看看我的代碼。在陣列中推動數據 - Angular/Ionic

錯誤消息時拋出: ionic.bundle.js:25642類型錯誤:無法讀取屬性 '標題' 未定義 的範圍在$ scope.createEx(app.js:63)。 在範圍$ scope.createEx (app.js:62)

的index.html

<script id="templates/addEx.html" type="text/ng-template"> 
     <ion-view view-title="GymHelper"> 
     <ion-content padding="true" ng-controller="OverallCtrl"> 
      <div class="list"> 
      <label class="item item-input item-floating-label"> 
       <span class="input-label">Exercise Title</span> 
       <input ng-model="exer.title" type="text" placeholder="Title"> 
      </label> 
      <label class="item item-input item-floating-label"> 
       <span class="input-label">Exercise Sets</span> 
       <input ng-model="exer.set" type="text" placeholder="Sets"> 
      </label> 
      <label class="item item-input item-floating-label"> 
       <span class="input-label">Exercise Reps</span> 
       <input ng-model="exer.rep" type="text" placeholder="Reps"> 
      </label> 
      <label class="item item-input item-floating-label"> 
       <span class="input-label">Extra Information</span> 
       <input ng-model"exer.inf" type="text" placeholder="Extra Information"> 
      </label> 
      <label class="item item-input item-select"> 
      <div class="input-label"> 
       Muscle 
      </div> 
      <select ng-model="selOption"> 
       <option>Chest</option> 
       <option>Biceps</option> 
       <option>Back</option> 
       <option>Stomach</option> 
       <option>Legs</option> 
       <option>Triceps</option> 
       <option>Shoulders</option> 
       <option>Traps</option> 
      </select> 
      </label> 
      </div> 
      <button class="button button-block button-positive" ng-click="createEx(exer)"> 
      Create Exercise 
      </button> 

     </ion-content> 
     </ion-view> 
    </script> 

App.js

app.controller('OverallCtrl', function($scope, $ionicListDelegate, $state) { 

    $scope.selOption == "Chest"; 

    $scope.createEx = function(exer) { 
    if($scope.selOption == "Chest"){ 
     $scope.chestEx.push({title: exer.title, sets: exer.set, reps: exer.rep, exInf: exer.inf}); 
     console.log("Pushed to Chest Array."); 
     $state.go('chest') 
    }; 
    } 

    $scope.chestEx = [ 

      {title: "Crowls", sets: 3, reps: 15, exInf: "Make 5 minute pause between Sets."}, 

        ] 

}) 
+0

它說,你要訪問屬性,'title',在'undefined'的頂部位置

$scope.chestEx = [ {title: "Crowls", sets: 3, reps: 15, exInf: "Make 5 minute pause between Sets."}, ] 

。意思是'exer'是'undefined'。你確定你將正確的值傳遞給'createEx'嗎? –

+0

嘗試在你的控制器中放置'$ scope.exer = {}'.. – JordanHendrix

+0

它仍然不起作用,但是沒有拋出錯誤信息 –

回答

0

請在$ scope.createEx功能

+0

仍然沒有工作。 –