简体   繁体   English

推入数组中的数据-角度/离子

[英]Pushing Data in Array - Angular/Ionic


Im working on an App, and i want to push Data in an Array, but it doesnt work. 我在一个应用程序上工作,我想将数据推送到一个数组中,但是不起作用。 Maybe you can take a look at my code. 也许您可以看看我的代码。

Error Message Thrown: ionic.bundle.js:25642 TypeError: Cannot read property 'title' of undefined at Scope.$scope.createEx (app.js:63) at Scope.$scope.createEx (app.js:62) 引发错误消息: ionic.bundle.js:25642 TypeError:无法在Scope。$ scope.createEx(app.js:63)读取Scope。$ scope.createEx(app.js:63)的未定义属性'title'

Index.html 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.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."},

                  ]

})

please position 请定位

 $scope.chestEx = [

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

                  ]

on top of $scope.createEx function 在$ scope.createEx函数之上

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM