0

私はangularjsアプリケーションと多くの問題に直面している初心者として取り組んでいます。私は2つの角度UIグリッドを持っています。テキストフィールドのユーザー入力に基づいて、UIグリッドに値を表示する必要があります。これを達成するのに苦労する。どんな提案も役に立ちます。 私のコードhereのデモをご覧ください。角度UIグリッドとユーザー入力に基づく値を表示

ユーザータイプ/アトランタはにテキストフィールドにテキストフィールド、シカゴからに選択し、SearchLocationsボタンをクリックすると、その名前AtlantaChicagoの下に表示されている値でグリッドを表示する必要があります。ユーザーがNewYorkとchicagoを入力すると、NewYorkChicagoという名前で表示される鳥の値が表示されます。テキストボックスに値が入力されていない場合、グリッドは表示されません。どんな提案も非常に役に立ちます。

HTMLコード:

<body style="padding-left:15px" ng-controller="searchController"> 
    <form class="form-inline"> 

    <div class="row"> 
     <div class="form-group" ng-controller="citiesCtrl"> 
      <label>From</label> 
      <input type="text" ng-model="places1" placeholder="Type Departure City" typeahead="item for item in items | filter:$viewValue | limitTo:8"> 
     </div> 
     <div class="form-group" ng-controller="citiesCtrl"> 
      <label>To</label> 
      <input type="text" ng-model="places2" placeholder="Type Destination City" typeahead="item for item in items | filter:$viewValue | limitTo:8"> 
     </div> 
    </div> 

    <input type="submit" value="SearchLocations" ng-submit="submit()"> 
    <div ng-repeat="user in users"> 
     <h3>{{user.name}}</h3> 
     <div ui-grid="{ data: user.details }" ng-show="user.show" class="myGrid"></div> 
    </div> 

</form> 
</body> 

JSコード:

angular.module('myApp', ['ngAnimate', 'ui.bootstrap','ngTouch', 'ui.grid', 'ui.grid.selection', 'ui.grid.edit','ui.grid.cellNav']); 
     angular.module('myApp').controller('citiesCtrl',function($scope){ 
      $scope. places = undefined; 
      $scope.items = ["Atlanta", "Chicago", "NewYork"]; 
      $scope.selectAction = function() { 
       console.log($scope.places1); 

      }; 
     }); 

    /*Controller for searchLocations button*/ 
     angular.module('myApp').controller('searchController', ['$scope', function($scope) { 
      $scope.submit = function() { 
       alert("in submit"); 
       if ($scope.places1) { 
        alert("inside the condition"); 
        /*       $scope.list.push(this.places1); 
        $scope.places1 = ''; 
        */      } 
      }; 
      $scope.users = [ 
       {'name' : 'AtlantaChicago', 
        'show' : true, 
        'details' : [ 
         {"Travel Date": "10/10/2014", commute:"Bus"}, 
         {"Travel Date": "10/11/2014", commute:"flight"}] 
       }, 
       {'name' : 'NewYorkChicago', 
        'show' : true, 
        'details': [ 
         {"Travel Date": "3/15/2016", commute:"flight"}, 
         {"Travel Date": "10/12/2016", commute:"flight"}, 
        ] 
       } 
      ]; 
      $scope.gridOptions = { 
       enableFiltering: true, 
       columnDefs: [ 
        { name: 'Travel Date', width: '5%'}, 
        { name: 'Departurecommute', enableFiltering: false, width: '12%' } 
       ], 
       rowHeight: 20, 
       enableHorizontalScrollbar:2 

      }; 
     }]); 

答えて

0

あなたが親スコープにplacesを定義する必要があります - searchController。この場合、お子様(citiesCtrl)はモデルを変更したときに継承して変更するため、親のsubmit()コールで変更された値にアクセスできます。それ以外の場合は、それぞれcitiesCtrlが独自のplaces変数を作成します。

Here is your updated example

関連する問題